Skip to content

Commit a4093c9

Browse files
authored
Merge pull request #3033 from slavapestov/declared-type-untangling
2 parents 004d85e + fc59abe commit a4093c9

File tree

81 files changed

+1005
-1060
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1005
-1060
lines changed

include/swift/AST/Decl.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,14 +2411,14 @@ class GenericTypeDecl : public TypeDecl, public DeclContext {
24112411
return GenericSig;
24122412
}
24132413

2414-
void setIsValidatingGenericSignature(bool ivgs = true) {
2415-
ValidatingGenericSignature = ivgs;
2414+
void setIsValidatingGenericSignature(bool validating=true) {
2415+
ValidatingGenericSignature = validating;
24162416
}
24172417

24182418
bool isValidatingGenericSignature() const {
24192419
return ValidatingGenericSignature;
24202420
}
2421-
2421+
24222422
// Resolve ambiguity due to multiple base classes.
24232423
using TypeDecl::getASTContext;
24242424
using DeclContext::operator new;
@@ -2847,12 +2847,15 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
28472847
return SearchedForFailableInits;
28482848
}
28492849

2850-
/// getDeclaredType - Retrieve the type declared by this entity.
2851-
Type getDeclaredType() const { return DeclaredTy; }
2852-
2853-
/// Compute the type (and declared type) of this nominal type.
2850+
/// Compute the type of this nominal type.
28542851
void computeType();
28552852

2853+
/// getDeclaredType - Retrieve the type declared by this entity, without
2854+
/// any generic parameters bound if this is a generic type.
2855+
Type getDeclaredType() const;
2856+
2857+
/// getDeclaredType - Retrieve the type declared by this entity, with
2858+
/// context archetypes bound if this is a generic type.
28562859
Type getDeclaredTypeInContext() const;
28572860

28582861
/// Get the "interface" type of the given nominal type, which is the
@@ -3437,7 +3440,8 @@ class ProtocolDecl : public NominalTypeDecl {
34373440
bool inheritsFrom(const ProtocolDecl *Super) const;
34383441

34393442
ProtocolType *getDeclaredType() const {
3440-
return reinterpret_cast<ProtocolType *>(DeclaredTy.getPointer());
3443+
return reinterpret_cast<ProtocolType *>(
3444+
NominalTypeDecl::getDeclaredType().getPointer());
34413445
}
34423446

34433447
SourceLoc getStartLoc() const { return ProtocolLoc; }

include/swift/AST/DiagnosticsParse.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ ERROR(disallowed_var_multiple_getset,none,
175175
"'var' declarations with multiple variables cannot have explicit"
176176
" getters/setters", ())
177177

178-
ERROR(disallowed_type,none,
179-
"type not allowed here", ())
180178
ERROR(disallowed_init,none,
181179
"initial value is not allowed here", ())
182180
ERROR(var_init_self_referential,none,
@@ -1289,6 +1287,10 @@ ERROR(redundant_class_requirement,none,
12891287
"redundant 'class' requirement", ())
12901288
ERROR(late_class_requirement,none,
12911289
"'class' must come first in the requirement list", ())
1290+
ERROR(where_without_generic_params,none,
1291+
"'where' clause cannot be attached to "
1292+
"%select{a non-generic|a protocol|an associated type}0 "
1293+
"declaration", (unsigned))
12921294

12931295
//------------------------------------------------------------------------------
12941296
// Conditional compilation parsing diagnostics

include/swift/AST/DiagnosticsSema.def

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,6 @@ NOTE(object_literal_resolve_import,none,
572572
"import %0 to use '%1' as the default %2 literal type",
573573
(StringRef, StringRef, StringRef))
574574

575-
ERROR(use_non_type_value,none,
576-
"%0 is not a type", (Identifier))
577-
NOTE(use_non_type_value_prev,none,
578-
"%0 declared here", (Identifier))
579575
ERROR(use_local_before_declaration,none,
580576
"use of local variable %0 before its declaration", (DeclName))
581577
ERROR(unsupported_existential_type,none,
@@ -1057,14 +1053,26 @@ ERROR(pattern_binds_no_variables,none,
10571053

10581054
// Generic types
10591055
ERROR(unsupported_generic_nested_in_type,none,
1060-
"generic type %0 nested in type %1 is not allowed",
1061-
(Identifier, Type))
1056+
"generic type %0 cannot be nested in type %1",
1057+
(Identifier, Identifier))
10621058
ERROR(unsupported_type_nested_in_generic_type,none,
1063-
"type %0 nested in generic type %1 is not allowed",
1064-
(Identifier, Type))
1059+
"type %0 cannot be nested in generic type %1",
1060+
(Identifier, Identifier))
1061+
ERROR(unsupported_type_nested_in_generic_extension,none,
1062+
"type %0 cannot be nested in extension of generic type %1",
1063+
(Identifier, Identifier))
10651064
ERROR(unsupported_type_nested_in_generic_function,none,
1066-
"type %0 nested in generic function %1 is not allowed",
1065+
"type %0 cannot be nested in generic function %1",
10671066
(Identifier, Identifier))
1067+
ERROR(unsupported_type_nested_in_protocol,none,
1068+
"type %0 cannot be nested in protocol %1",
1069+
(Identifier, Identifier))
1070+
ERROR(unsupported_type_nested_in_protocol_extension,none,
1071+
"type %0 cannot be nested in protocol extension of %1",
1072+
(Identifier, Identifier))
1073+
ERROR(unsupported_nested_protocol,none,
1074+
"protocol %0 cannot be nested inside another declaration",
1075+
(Identifier))
10681076

10691077
// Type aliases
10701078
ERROR(circular_type_alias,none,
@@ -1115,8 +1123,6 @@ ERROR(extension_constrained_inheritance,none,
11151123
"inheritance clause", (Type))
11161124
ERROR(extension_protocol_inheritance,none,
11171125
"extension of protocol %0 cannot have an inheritance clause", (Type))
1118-
ERROR(extension_protocol_type_definition,none,
1119-
"type %0 cannot be defined within a protocol extension", (DeclName))
11201126
ERROR(extension_protocol_via_typealias,none,
11211127
"protocol %0 in the module being compiled cannot be extended via a "
11221128
"typealias", (Type))

include/swift/Parse/Parser.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -655,16 +655,15 @@ class Parser {
655655
PD_Default = 0,
656656
PD_AllowTopLevel = 1 << 1,
657657
PD_HasContainerType = 1 << 2,
658-
PD_DisallowNominalTypes = 1 << 3,
659-
PD_DisallowInit = 1 << 4,
660-
PD_AllowDestructor = 1 << 5,
661-
PD_AllowEnumElement = 1 << 6,
662-
PD_InProtocol = 1 << 7,
663-
PD_InClass = 1 << 8,
664-
PD_InExtension = 1 << 9,
665-
PD_InStruct = 1 << 10,
666-
PD_InEnum = 1 << 11,
667-
PD_InLoop = 1 << 12
658+
PD_DisallowInit = 1 << 3,
659+
PD_AllowDestructor = 1 << 4,
660+
PD_AllowEnumElement = 1 << 5,
661+
PD_InProtocol = 1 << 6,
662+
PD_InClass = 1 << 7,
663+
PD_InExtension = 1 << 8,
664+
PD_InStruct = 1 << 9,
665+
PD_InEnum = 1 << 10,
666+
PD_InLoop = 1 << 11
668667
};
669668

670669
/// Options that control the parsing of declarations.
@@ -1240,7 +1239,15 @@ class Parser {
12401239
ParserResult<GenericParamList> parseGenericParameters();
12411240
ParserResult<GenericParamList> parseGenericParameters(SourceLoc LAngleLoc);
12421241
ParserResult<GenericParamList> maybeParseGenericParams();
1243-
ParserStatus parseFreestandingGenericWhereClause(GenericParamList *&GPList);
1242+
1243+
enum class WhereClauseKind : unsigned {
1244+
Declaration,
1245+
Protocol,
1246+
AssociatedType
1247+
};
1248+
ParserStatus
1249+
parseFreestandingGenericWhereClause(GenericParamList *&GPList,
1250+
WhereClauseKind kind=WhereClauseKind::Declaration);
12441251

12451252
ParserStatus parseGenericWhereClause(SourceLoc &WhereLoc,
12461253
SmallVectorImpl<RequirementRepr> &Requirements,

include/swift/SIL/TypeLowering.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,6 @@ struct SILConstantInfo {
380380
return SILType::getPrimitiveObjectType(SILFnType);
381381
}
382382

383-
ArrayRef<Substitution> getForwardingSubstitutions(ASTContext &C) {
384-
if (!ContextGenericParams)
385-
return { };
386-
return ContextGenericParams->getForwardingSubstitutions(C);
387-
}
388-
389383
friend bool operator==(SILConstantInfo lhs, SILConstantInfo rhs) {
390384
return lhs.FormalInterfaceType == rhs.FormalInterfaceType &&
391385
lhs.LoweredInterfaceType == rhs.LoweredInterfaceType &&

0 commit comments

Comments
 (0)