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

[SR-2520] Type alias is lost when applying @escaping-ness #45125

Open
jtbandes opened this issue Aug 30, 2016 · 4 comments
Open

[SR-2520] Type alias is lost when applying @escaping-ness #45125

jtbandes opened this issue Aug 30, 2016 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@jtbandes
Copy link
Collaborator

Previous ID SR-2520
Radar None
Original Reporter @jtbandes
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 696cc521de25a6df6bd6323fe4845bd0

relates to:

  • SR-2529 Keep attribute((noescape)) when importing Clang types
  • SR-2406 Print attribute((noescape)) in the generated header

Issue Description:

When applyNonEscapingFromContext() is applied to a NameAliasType wrapping a FunctionType, the result is just a FunctionType, i.e. the NameAlias is lost. This means things like PrintAsObjC will not use the original name, but the raw function type.

@slavapestov wrote this in a FIXME, but I wanted to track it here so I have something to link to.

    // FIXME: It would be better to add a new AttributedType sugared type,
    // which would wrap the NameAliasType or ParenType, and apply the
    // isNoEscape bit when de-sugaring.
@milseman
Copy link
Mannequin

milseman mannequin commented Sep 23, 2016

Could you please attach something that repros this?
With #4905 in, I have some tests that don't strip the typealias, and correctly print the @escaping as needed. But, there may be other code paths that trigger the problem than what I'm testing.

@jtbandes
Copy link
Collaborator Author

Have a look at https://github.com/apple/swift/blob/e06d676d756ce95bd7c32a3029d165c7be5fd4b4/test/PrintAsObjC/imported-block-typedefs.swift

Writing these is when I discovered this issue. You may find the comments there helpful in reproducing it. However I'm not at my computer right now so I can't provide any more than a link until later 🙂

@davezarzycki
Copy link
Collaborator

Why complicate the type system with a new type? Why not build a sugar reconstitution APIs? For example:

   bool defaultNoEscape = isFunctionParam;
 
-  // Desugar here
-  auto *funcTy = ty->castTo<FunctionType>();
+  // Partial desugaring means that desugaring stops once we find the type we want
+  auto *funcTy = ty->partialDesugarCastTo<FunctionType>();
   auto extInfo = funcTy->getExtInfo();
   if (defaultNoEscape && !extInfo.isNoEscape()) {
     extInfo = extInfo.withNoEscape();
 
-    // We lost the sugar to flip the isNoEscape bit.
-    //
-    // FIXME: It would be better to add a new AttributedType sugared type,
-    // which would wrap the NameAliasType or ParenType, and apply the
-    // isNoEscape bit when de-sugaring.
-    // <https://bugs.swift.org/browse/SR-2520>
-    return FunctionType::get(funcTy->getInput(), funcTy->getResult(), extInfo);
+    auto newTy = FunctionType::get(funcTy->getInput(), funcTy->getResult(), extInfo);
+    return ty->rebuildSugar(/*orig*/funcTy, /*replacement*/newTy);
   }
 
   // Note: original sugared type
   return ty;

@milseman
Copy link
Mannequin

milseman mannequin commented Apr 10, 2019

This shouldn't be assigned to me.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants