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

attributes to control mangling and stripping with @no_mangle, @no_strip #81

Open
k2d222 opened this issue Feb 12, 2025 · 2 comments
Open

Comments

@k2d222
Copy link
Contributor

k2d222 commented Feb 12, 2025

There are cases where you would want these things for one specific declaration:

  • skip name mangling.
    Reason: only the root module declarations are not mangled, what if you want to access some other declaration?
  • keep a declaration even if it is not used.
    Reason: incremental compilation, glueing code together after linking, function-scope const-asserts...

this could be configured in the linker, but new attributes could also achieve this, example:

@no_strip
fn please_keep_this() { // this declaration and its dependencies will be kept in the final WGSL, even if not used by entrypoints.
  // ...
}

@no_mangle
fn some_declaration() { // this declaration will not be mangled, even if it is not in the root module.
  // ...
}

fn some_function() {
  @no_mangle
  subgroupExclusiveMul(x); // subgroupExclusiveMul is a new WGSL builtin function that may not be known by the linker yet...
}

related: #45

@mighdoll
Copy link
Contributor

mighdoll commented Feb 12, 2025

Partially linking something at build time and completing the link at runtime sounds pretty interesting. What are the user scenarios? I'm trying to understand how persistent the partially linked code is, what's supplied at runtime vs. build time, how this relates to potentially pre-parsing to an AST, etc.

for skipping name mangling for the host interface, could #65 be our solution? (i.e. host visible names need to be in the unmangled root module one way or another)

@k2d222
Copy link
Contributor Author

k2d222 commented Feb 12, 2025

mangling: @publish is a preferable solution yes! no action at a distance, no risks of collision, one-fits-all solution..

stripping: well my initial thought was that sometimes you want to compile down code that doesn't have entrypoints, if for example it depends on a big stdlib and you want to bundle it down to one file. Just mark the functions you want to keep with @no_strip (@keep might be a better name).

Other use-case, you want to keep dead code to make sure it is valid with naga/tint.

just adding that those attributes are not really a priority nor a necessity (can be achieved by configuring linker), just sharing ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

2 participants