Skip to content

Fix mangling of '@noDerivative' and unify function attribute mangling operators. #36772

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

Merged
merged 2 commits into from
Apr 8, 2021

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Apr 6, 2021

  • Unify mangling operators for attributes async, @Sendable, and @differentiable under a single Y operator. Free up operators J and j.

    async ::= 'Ya'                             // 'async' annotation on function types
    sendable ::= 'Yb'                          // @Sendable on function types
    throws ::= 'K'                             // 'throws' annotation on function types
    differentiable ::= 'Yjf'                   // @differentiable(_forward) on function type
    differentiable ::= 'Yjr'                   // @differentiable(reverse) on function type
    differentiable ::= 'Yjd'                   // @differentiable on function type
    differentiable ::= 'Yjl'                   // @differentiable(_linear) on function type
    
  • @noDerivative was not mangled in function types, and was resolved incorrectly when there's an ownership specifier. It is fixed by this patch with the following changes:

    • Add NoDerivative demangle node represented by a Yk operator.
      list-type ::= type identifier? 'Yk'? 'z'? 'h'? 'n'? 'd'?  // type with optional label, '@noDerivative', inout convention, shared convention, owned convention, and variadic specifier
      
    • Fix NoDerivative's overflown offset in ParameterTypeFlags (7 -> 6).
    • In type decoder and type resolver where attributed type nodes are processed, add support for nested attributed nodes, e.g. inout @noDerivative T.
    • Add TypeResolverContext::InoutFunctionInput so that when we resolve an inout @noDerivative T parameter, the @noDerivative T checking logic won't get a TypeResolverContext::None set by the caller.

Resolves rdar://76299796 and rdar://75916833.

@rxwei rxwei requested review from DougGregor and joshnewnham April 6, 2021 10:07
@rxwei
Copy link
Contributor Author

rxwei commented Apr 6, 2021

@swift-ci please test

@rxwei rxwei requested a review from eeckstein April 6, 2021 10:08
@swift-ci
Copy link
Contributor

swift-ci commented Apr 6, 2021

Build failed
Swift Test Linux Platform
Git Sha - 6a1e4e76e4715434758b72d3518a3c6404d040eb

Copy link

@joshnewnham joshnewnham left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

Can you pease not use a top-level operator ('k') for this?
We only have very few left and we should not "waste" them for something which is not critical for symbol sizes.

@rxwei
Copy link
Contributor Author

rxwei commented Apr 6, 2021

Can you pease not use a top-level operator ('k') for this?
We only have very few left and we should not "waste" them for something which is not critical for symbol sizes.

Could you suggest an existing operator that I should fold under?

@eeckstein
Copy link
Contributor

You can make a sub-operator of 'TJ', e.g. 'TJk'.
BTW, can you also change 'j' to e.g. 'TJj'?

@rxwei
Copy link
Contributor Author

rxwei commented Apr 6, 2021

Should the same rationale apply to AsyncAnnotation ('Y')? I could make Y be an umbrella operator for annotations/markers if you think that is appropriate, then Ya could be async and Yk could be @noDerivative.

Similarly, J is currently used only for Node::Kind::ConcurrentFunctionType, which is an annotation just like Node::Kind::DifferentiableFunctionType. I can move both of them under Y/J if there are no objections, e.g. Yj for @Sendable and YJ for @differentiable.

@rxwei rxwei changed the title [AutoDiff] Fix mangling of '@noDerivative' in function types. Fix mangling of '@noDerivative' and unify function attribute mangling operators. Apr 7, 2021
@rxwei
Copy link
Contributor Author

rxwei commented Apr 7, 2021

In 3c5b367 I made the change I proposed above. PTAL.

async ::= 'Ya'                             // 'async' annotation on function types
sendable ::= 'Yb'                          // @Sendable on function types
throws ::= 'K'                             // 'throws' annotation on function types
differentiable ::= 'Yjf'                   // @differentiable(_forward) on function type
differentiable ::= 'Yjr'                   // @differentiable(reverse) on function type
differentiable ::= 'Yjd'                   // @differentiable on function type
differentiable ::= 'Yjl'                   // @differentiable(_linear) on function type

@rxwei rxwei force-pushed the 75916833-noderivative branch from 3c5b367 to f41e130 Compare April 7, 2021 02:29
@rxwei rxwei requested a review from eeckstein April 7, 2021 02:32
@rxwei rxwei force-pushed the 75916833-noderivative branch from f41e130 to a626cdb Compare April 7, 2021 02:43
Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Skimmed this, but it LGTM

@rxwei rxwei force-pushed the 75916833-noderivative branch from a626cdb to 53b5fc9 Compare April 7, 2021 04:42
@rxwei
Copy link
Contributor Author

rxwei commented Apr 7, 2021

@swift-ci please test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

Thanks, the mangling scheme looks good now.
I just have a few comments on the implementation.

@rxwei rxwei force-pushed the 75916833-noderivative branch from 53b5fc9 to 52bf864 Compare April 7, 2021 08:23
@rxwei
Copy link
Contributor Author

rxwei commented Apr 7, 2021

@swift-ci please test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@rxwei rxwei force-pushed the 75916833-noderivative branch from 52bf864 to b8a5de5 Compare April 7, 2021 10:12
@rxwei
Copy link
Contributor Author

rxwei commented Apr 7, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Apr 7, 2021

Build failed
Swift Test OS X Platform
Git Sha - b8a5de51e078e6f28fe099d358aeafd90fe88272

@rxwei rxwei force-pushed the 75916833-noderivative branch from b8a5de5 to faec5d0 Compare April 7, 2021 22:41
`@noDerivative` was not mangled in function types, and was resolved incorrectly when there's an ownership specifier. It is fixed by this patch with the following changes:

* Add `NoDerivative` demangle node represented by a `k` operator.
    ```
    list-type ::= type identifier? 'k'? 'z'? 'h'? 'n'? 'd'?  // type with optional label, '@noDerivative', inout convention, shared convention, owned convention, and variadic specifier
    ```
* Fix `NoDerivative`'s overflown offset in `ParameterTypeFlags` (`7` -> `6`).
* In type decoder and type resolver where attributed type nodes are processed, add support for nested attributed nodes, e.g. `inout @noDerivative T`.
* Add `TypeResolverContext::InoutFunctionInput` so that when we resolve an `inout @noDerivative T` parameter, the `@noDerivative T` checking logic won't get a `TypeResolverContext::None` set by the caller.

Resolves rdar://75916833.
@rxwei rxwei force-pushed the 75916833-noderivative branch from faec5d0 to 171c92c Compare April 7, 2021 22:45
@rxwei
Copy link
Contributor Author

rxwei commented Apr 7, 2021

@swift-ci please test and merge

…and `@noDerivative`.

Repurpose mangling operator `Y` as an umbrella operator that covers new attributes on function types. Free up operators `J`, `j`, and `k`.

```
async ::= 'Ya'                             // 'async' annotation on function types
sendable ::= 'Yb'                          // @sendable on function types
throws ::= 'K'                             // 'throws' annotation on function types
differentiable ::= 'Yjf'                   // @differentiable(_forward) on function type
differentiable ::= 'Yjr'                   // @differentiable(reverse) on function type
differentiable ::= 'Yjd'                   // @differentiable on function type
differentiable ::= 'Yjl'                   // @differentiable(_linear) on function type
```

Resolves rdar://76299796.
@rxwei rxwei force-pushed the 75916833-noderivative branch from 171c92c to fb66de6 Compare April 8, 2021 00:49
@rxwei
Copy link
Contributor Author

rxwei commented Apr 8, 2021

@swift-ci please test and merge

@rxwei
Copy link
Contributor Author

rxwei commented Apr 8, 2021

@swift-ci please test macos

1 similar comment
@rxwei
Copy link
Contributor Author

rxwei commented Apr 8, 2021

@swift-ci please test macos

@rxwei rxwei merged commit fd06683 into swiftlang:main Apr 8, 2021
@rxwei rxwei deleted the 75916833-noderivative branch April 8, 2021 16:40
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.

5 participants