Skip to content

Portability checking and target_feature #17

Open
@Ericson2314

Description

@Ericson2314

The portability lint as planned just lints the code that did not get cfg'd away. But an extension (raised many time including by me in #8 (comment)) would have it be done on everything. This entails delaying the pruning of cfg-dead code until after name resolution, or even type checking.

I always assumed this would be a long ways off, but I just realized something vary similar has been proposed with with inlining and target_feature. For the static #[target_feature], the inline rules are just a hard-error version of the compatibility lint, which is great! (I hope in a future epoch the compatibility lint can be made a hard error.). But for cfg!(target_feature), we have some very interesting things going on:

  1. Portability per node. For a fully analyzed cfg!(target_feature) we can look at the portability per mode of the CFG instead of per item. We'd probably want a difference syntax but the short story is that different branches of an if cfg!(...) have statically known portability, the dynamism is just the choice of edge. For cfg_feature_enabled! it's just the same except no branches must be pruned in the end.
  2. Selective hygiene: A function must always be statically safe to call/inline if it is safe at all, but we "break" normal lexical rules to allow "improving" the interpretation of the formula. This can be formalized as passing in an exact portability as a static-parameter to be monomorphized.

More broadly, the concept of compiling for multiple variations of a platforms neatly extends into compiling for multiple platforms. #[target_feature] is just #[cfg(target_feature ...)] where the target_feature is neither true nor false in all current platforms. There is very little conceptual overhead in extending this to interpreting arbitrary cfg formulae over arbitrary sets of "active" (concurrently targeted) models. Given that one general system of "delayed cfg resolution" can implement both features, I'd strongly consider planning that.

As an aside, I guess we might as well track over areas of overlap between these two features in this issue too.

CC @gnzlbg

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions