Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llcppcfg: sort includes #121

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

llcppcfg: sort includes #121

wants to merge 11 commits into from

Conversation

tsingbx
Copy link
Contributor

@tsingbx tsingbx commented Jan 2, 2025

No description provided.

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.01%. Comparing base (81acd8d) to head (2e74219).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #121   +/-   ##
=======================================
  Coverage   98.01%   98.01%           
=======================================
  Files          15       15           
  Lines        1864     1864           
=======================================
  Hits         1827     1827           
  Misses         26       26           
  Partials       11       11           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

types/types.go Outdated Show resolved Hide resolved
types/types.go Outdated Show resolved Hide resolved
@tsingbx tsingbx force-pushed the cmd/llcppcfg branch 8 times, most recently from 629022a to 4371d4a Compare January 3, 2025 02:57
@tsingbx tsingbx force-pushed the cmd/llcppcfg branch 4 times, most recently from 1eb4b47 to 4b1e1bc Compare January 3, 2025 07:37
Comment on lines 300 to 299
sort.Slice(cflagEntry.ObjFiles, func(i, j int) bool {
return len(cflagEntry.ObjFiles[i].Deps) > len(cflagEntry.ObjFiles[j].Deps)
})
Copy link
Contributor

@luoliwoshang luoliwoshang Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个实现看起来是通过头文件的依赖数量来决定其生成的include顺序,按照依赖数量排序,并不能反映适合的文件处理顺序。

考虑以下场景
main.h

#include "common_type.h"
#include a.h

common_type.h

typedef struct Foo {
    int a;
} Foo;

a.h

#include "a_common.h"
#include  "a_type.h"
#include  "a_compact.h"
Foo *fn();

按照这个由 头文件的依赖数量 的逻辑来输出的include顺序会是 a.h(3) , main.h(2), common_type.h(0),但这个处理顺序一定是非预期的 ,a.h 这里使用Foo时,还没定义Foo类型。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无论怎么处理,都必须要有这个,同级头文件,根据什么来判断?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无论怎么处理,都必须要有这个,同级头文件,根据什么来判断?

  • 同级别的头文件通过其引用include关系来处理其顺序。

  • 当前根据依赖数量的逻辑来给出include处理顺序并不合适,该逻辑对于我上面提出的用例已经不能正确表达了。

@tsingbx tsingbx force-pushed the cmd/llcppcfg branch 2 times, most recently from 354d76f to 81a0e1a Compare January 3, 2025 10:53
@tsingbx tsingbx force-pushed the cmd/llcppcfg branch 5 times, most recently from 5d6c99d to 6c6d1f5 Compare January 4, 2025 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants