Skip to content

ModuleInterface: Resolve types of CustomAttrs when printing #69560

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/AST/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,9 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
break;
}
case DAK_Custom: {

auto attr = cast<CustomAttr>(this);
if (auto type = attr->getType()) {
if (auto type =
D->getResolvedCustomAttrType(const_cast<CustomAttr *>(attr))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should getType() be made private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a lot of existing uses of getType() that don't need to go through something like getResolvedCustomAttrType() because they get called on a CustomAttr that was retrieved via a request that resolves the type. It's only when printing or serializing that we work with CustomAttrs abstractly (without knowing that we want a result builder, property wrapper, etc.) and therefore need this.

// Print custom attributes only if the attribute decl is accessible.
// FIXME: rdar://85477478 They should be rejected.
if (auto attrDecl = type->getNominalOrBoundGenericNominal()) {
Expand Down
10 changes: 3 additions & 7 deletions test/ModuleInterface/lazy-typecheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -typecheck -emit-module-interface-path %t/lazy/lazy_typecheck.swiftinterface -enable-library-evolution -parse-as-library -package-name Package -DFLAG -debug-forbid-typecheck-prefix NoTypecheck -experimental-lazy-typecheck
// RUN: rm -rf %t/lazy/*.swiftmodule
// RUN: %target-swift-frontend -package-name ClientPackage -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -I %t/lazy
// FIXME: The emitted interfaces should be identical
// diff -u %t/baseline/lazy_typecheck.swiftinterface %t/lazy/lazy_typecheck.swiftinterface
// RUN: diff -u %t/baseline/lazy_typecheck.swiftinterface %t/lazy/lazy_typecheck.swiftinterface

// (3) Same as (2), but with -experimental-skip-all-function-bodies added.
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -typecheck -emit-module-interface-path %t/lazy-skip-all/lazy_typecheck.swiftinterface -enable-library-evolution -parse-as-library -package-name Package -DFLAG -debug-forbid-typecheck-prefix NoTypecheck -experimental-lazy-typecheck -experimental-skip-non-exportable-decls -experimental-skip-all-function-bodies
// RUN: rm -rf %t/lazy-skip-all/*.swiftmodule
// RUN: %target-swift-frontend -package-name ClientPackage -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -I %t/lazy-skip-all
// FIXME: The emitted interfaces should be identical
// diff -u %t/baseline/lazy_typecheck.swiftinterface %t/lazy-skip-all/lazy_typecheck.swiftinterface
// RUN: diff -u %t/baseline/lazy_typecheck.swiftinterface %t/lazy-skip-all/lazy_typecheck.swiftinterface

// (4) Same as (2), but with -experimental-skip-non-inlinable-function-bodies added.
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -typecheck -emit-module-interface-path %t/lazy-skip-non-inlinable/lazy_typecheck.swiftinterface -enable-library-evolution -parse-as-library -package-name Package -DFLAG -debug-forbid-typecheck-prefix NoTypecheck -experimental-lazy-typecheck -experimental-skip-non-inlinable-function-bodies
// RUN: rm -rf %t/lazy-skip-non-inlinable/*.swiftmodule
// RUN: %target-swift-frontend -package-name ClientPackage -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -I %t/lazy-skip-non-inlinable
// FIXME: The emitted interfaces should be identical
// diff -u %t/baseline/lazy_typecheck.swiftinterface %t/lazy-skip-non-inlinable/lazy_typecheck.swiftinterface

// RUN: diff -u %t/baseline/lazy_typecheck.swiftinterface %t/lazy-skip-non-inlinable/lazy_typecheck.swiftinterface