Skip to content
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
2 changes: 1 addition & 1 deletion include/swift/AST/DeclAttr.def
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ SIMPLE_DECL_ATTR(_alwaysEmitIntoClient, AlwaysEmitIntoClient,
83)

SIMPLE_DECL_ATTR(_implementationOnly, ImplementationOnly,
OnImport | OnFunc | OnConstructor | OnVar | OnSubscript | OnStruct,
OnImport | OnFunc | OnConstructor | OnVar | OnSubscript | OnStruct | OnClass | OnEnum,
UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | UnreachableInABIAttr,
84)

Expand Down
14 changes: 7 additions & 7 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -3848,7 +3848,7 @@ ERROR(decl_from_hidden_module,none,
"C++ types from imported module %2 do not support library evolution|"
"it was imported via the internal bridging header|"
"%2 was not imported publicly|"
"it is a struct marked '@_implementationOnly'}3",
"%0 is marked '@_implementationOnly'}3",
(const Decl *, unsigned, Identifier, unsigned))
ERROR(typealias_desugars_to_type_from_hidden_module,none,
"%0 aliases '%1.%2' and cannot be used %select{here|"
Expand All @@ -3867,7 +3867,7 @@ ERROR(typealias_desugars_to_type_from_hidden_module,none,
"C++ types from imported module %4 do not support library evolution|"
"it was imported via the internal bridging header|"
"%4 was not imported publicly|"
"it is a struct marked '@_implementationOnly'}5",
"%0 is marked '@_implementationOnly'}5",
(const TypeAliasDecl *, StringRef, StringRef, unsigned, Identifier, unsigned))
ERROR(conformance_from_implementation_only_module,none,
"cannot use conformance of %0 to %1 %select{here|as property wrapper here|"
Expand All @@ -3884,7 +3884,7 @@ ERROR(conformance_from_implementation_only_module,none,
"C++ types from imported module %3 do not support library evolution|"
"it was imported via the internal bridging header|"
"%3 was not imported publicly|"
"it is a struct marked '@_implementationOnly'}4",
"%0 is marked '@_implementationOnly'}4",
(Type, Identifier, unsigned, Identifier, unsigned))
NOTE(assoc_conformance_from_implementation_only_module,none,
"in associated type %0 (inferred as %1)", (Type, Type))
Expand Down Expand Up @@ -3949,8 +3949,8 @@ ERROR(implementation_only_override_import_without_attr,none,
"override of %kindonly0 imported as implementation-only must be declared "
"'@_implementationOnly'",
(const ValueDecl *))
ERROR(implementation_only_on_structs_feature,none,
"'@_implementationOnly' on structs requires "
ERROR(implementation_only_on_types_feature,none,
"'@_implementationOnly' on a type requires "
"'-enable-experimental-feature CheckImplementationOnly'", ())

ERROR(import_attr_conflict,none,
Expand Down Expand Up @@ -7353,7 +7353,7 @@ ERROR(inlinable_decl_ref_from_hidden_module,
"C++ APIs from imported module %2 do not support library evolution|"
"it was imported via the internal bridging header|"
"%2 was not imported publicly|"
"it is a struct marked '@_implementationOnly'}3",
"%0 is marked '@_implementationOnly'}3",
(const ValueDecl *, unsigned, Identifier, unsigned))

ERROR(inlinable_typealias_desugars_to_type_from_hidden_module,
Expand All @@ -7366,7 +7366,7 @@ ERROR(inlinable_typealias_desugars_to_type_from_hidden_module,
"C++ types from imported module %4 do not support library evolution|"
"it was imported via the internal bridging header|"
"%4 was not imported publicly|"
"it is a struct marked '@_implementationOnly'}5",
"%0 is marked '@_implementationOnly'}5",
(const TypeAliasDecl *, StringRef, StringRef, unsigned, Identifier, unsigned))

NOTE(missing_import_inserted,
Expand Down
13 changes: 13 additions & 0 deletions lib/AST/Availability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,19 @@ bool swift::isExported(const ValueDecl *VD) {
if (property->isLayoutExposedToClients(/*applyImplicit=*/true))
return true;

// Is this a type exposed by default in a non-resilient module?
if (isa<NominalTypeDecl>(VD) &&
VD->getASTContext().LangOpts.hasFeature(
Feature::CheckImplementationOnly) &&
VD->getDeclContext()->getParentModule()->getResilienceStrategy() !=
ResilienceStrategy::Resilient &&
!VD->getAttrs().hasAttribute<ImplementationOnlyAttr>())
return true;

// Case of an enum not marked @_implementationOnly in a non-resilient module?
if (auto *EED = dyn_cast<EnumElementDecl>(VD))
return isExported(EED->getParentEnum());

return false;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4995,12 +4995,12 @@ AttributeChecker::visitImplementationOnlyAttr(ImplementationOnlyAttr *attr) {
return;
}

// @_implementationOnly on structs only applies to non-public types.
auto *VD = cast<ValueDecl>(D);
if (isa<StructDecl>(VD)) {

// @_implementationOnly on types only applies to non-public types.
if (isa<NominalTypeDecl>(D)) {
if (!Ctx.LangOpts.hasFeature(Feature::CheckImplementationOnly)) {
diagnoseAndRemoveAttr(attr,
diag::implementation_only_on_structs_feature);
diagnoseAndRemoveAttr(attr, diag::implementation_only_on_types_feature);
return;
}

Expand Down
7 changes: 7 additions & 0 deletions test/Sema/Inputs/implementation-only-imports/directs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ extension StructFromIndirect {
set {}
}
}

public struct RawTypeFromDirect : Equatable, ExpressibleByIntegerLiteral {
public typealias IntegerLiteralType = Int
public init(integerLiteral: Int) {}
}

public protocol ProtocolFromDirect { }
Loading