Skip to content

Commit 9de8200

Browse files
authored
Merge pull request #12595 from slavapestov/impressive-endless-regressions
Fixing various regressions
2 parents 4bf4643 + 93c80da commit 9de8200

23 files changed

+170
-70
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ ERROR(expected_parameter_type,PointsToFirstBadToken,
833833
ERROR(expected_parameter_name,PointsToFirstBadToken,
834834
"expected parameter name followed by ':'", ())
835835
ERROR(expected_parameter_colon,PointsToFirstBadToken,
836-
"expected ':' following argumant label and parameter name", ())
836+
"expected ':' following argument label and parameter name", ())
837837
ERROR(missing_parameter_type,PointsToFirstBadToken,
838838
"parameter requires an explicit type", ())
839839
ERROR(multiple_parameter_ellipsis,none,

include/swift/AST/Module.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "swift/Basic/OptionSet.h"
2828
#include "swift/Basic/SourceLoc.h"
2929
#include "swift/Basic/STLExtras.h"
30-
#include "swift/Parse/Token.h"
3130
#include "llvm/ADT/ArrayRef.h"
3231
#include "llvm/ADT/DenseSet.h"
3332
#include "llvm/ADT/SetVector.h"
@@ -72,6 +71,7 @@ namespace swift {
7271
class ProtocolDecl;
7372
struct PrintOptions;
7473
class ReferencedNameTracker;
74+
class Token;
7575
class TupleType;
7676
class Type;
7777
class TypeRefinementContext;
@@ -1076,19 +1076,11 @@ class SourceFile final : public FileUnit {
10761076
out << str << '\n';
10771077
}
10781078

1079-
std::vector<Token> &getTokenVector() {
1080-
assert(shouldKeepTokens() && "Disabled");
1081-
return *AllCorrectedTokens;
1082-
}
1079+
std::vector<Token> &getTokenVector();
10831080

1084-
ArrayRef<Token> getAllTokens() const {
1085-
assert(shouldKeepTokens() && "Disabled");
1086-
return *AllCorrectedTokens;
1087-
}
1081+
ArrayRef<Token> getAllTokens() const;
10881082

1089-
bool shouldKeepTokens() const {
1090-
return (bool)AllCorrectedTokens;
1091-
}
1083+
bool shouldKeepTokens() const;
10921084

10931085
syntax::SourceFileSyntax getSyntaxRoot() const;
10941086

include/swift/Parse/Parser.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,10 @@ class Parser {
787787
bool parseTypeAttributeList(VarDecl::Specifier &Specifier,
788788
SourceLoc &SpecifierLoc,
789789
TypeAttributes &Attributes) {
790-
if (Tok.isAny(tok::at_sign, tok::kw_inout, tok::kw___shared, tok::kw___owned))
790+
if (Tok.isAny(tok::at_sign, tok::kw_inout) ||
791+
(Tok.is(tok::identifier) &&
792+
(Tok.getRawText().equals("__shared") ||
793+
Tok.getRawText().equals("__owned"))))
791794
return parseTypeAttributeListPresent(Specifier, SpecifierLoc, Attributes);
792795
return false;
793796
}

include/swift/Parse/Token.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,17 @@ class Token {
179179
/// used
180180
bool canBeArgumentLabel() const {
181181
// Identifiers, escaped identifiers, and '_' can be argument labels.
182-
if (is(tok::identifier) || isEscapedIdentifier() || is(tok::kw__))
182+
if (is(tok::identifier) || isEscapedIdentifier() || is(tok::kw__)) {
183+
// ... except for '__shared' and '__owned'.
184+
if (getRawText().equals("__shared") ||
185+
getRawText().equals("__owned"))
186+
return false;
187+
183188
return true;
189+
}
184190

185-
// 'let', 'var', 'inout', '__shared', and '__owned'
186-
// cannot be argument labels.
187-
if (isAny(tok::kw_let, tok::kw_var, tok::kw_inout,
188-
tok::kw___owned, tok::kw___shared))
191+
// 'let', 'var', and 'inout' cannot be argument labels.
192+
if (isAny(tok::kw_let, tok::kw_var, tok::kw_inout))
189193
return false;
190194

191195
// All other keywords can be argument labels.

include/swift/Serialization/ModuleFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
5454
/// in source control, you should also update the comment to briefly
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
57-
const uint16_t VERSION_MINOR = 373; // Last change: destructure
57+
const uint16_t VERSION_MINOR = 374; // Last change: has forced static dispatch
5858

5959
using DeclID = PointerEmbeddedInt<unsigned, 31>;
6060
using DeclIDField = BCFixed<31>;
@@ -955,6 +955,7 @@ namespace decls_block {
955955
BCFixed<1>, // explicitly objc?
956956
SelfAccessKindField, // self access kind
957957
BCFixed<1>, // has dynamic self?
958+
BCFixed<1>, // has forced static dispatch?
958959
BCFixed<1>, // throws?
959960
BCVBR<5>, // number of parameter patterns
960961
GenericEnvironmentIDField, // generic environment

include/swift/Syntax/TokenKinds.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ DECL_KEYWORD(struct)
140140
DECL_KEYWORD(subscript)
141141
DECL_KEYWORD(typealias)
142142
DECL_KEYWORD(var)
143-
DECL_KEYWORD(__shared)
144-
DECL_KEYWORD(__owned)
145143

146144
DECL_KEYWORD(fileprivate)
147145
DECL_KEYWORD(internal)

lib/AST/Module.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "swift/AST/ProtocolConformance.h"
3535
#include "swift/Basic/Compiler.h"
3636
#include "swift/Basic/SourceManager.h"
37+
#include "swift/Parse/Token.h"
3738
#include "swift/Syntax/SyntaxNodes.h"
3839
#include "swift/Syntax/SyntaxParsingContext.h"
3940
#include "clang/Basic/Module.h"
@@ -1364,6 +1365,20 @@ SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,
13641365

13651366
SourceFile::~SourceFile() { delete &SyntaxInfo; }
13661367

1368+
std::vector<Token> &SourceFile::getTokenVector() {
1369+
assert(shouldKeepTokens() && "Disabled");
1370+
return *AllCorrectedTokens;
1371+
}
1372+
1373+
ArrayRef<Token> SourceFile::getAllTokens() const {
1374+
assert(shouldKeepTokens() && "Disabled");
1375+
return *AllCorrectedTokens;
1376+
}
1377+
1378+
bool SourceFile::shouldKeepTokens() const {
1379+
return (bool)AllCorrectedTokens;
1380+
}
1381+
13671382
bool FileUnit::walk(ASTWalker &walker) {
13681383
SmallVector<Decl *, 64> Decls;
13691384
getTopLevelDecls(Decls);

lib/IRGen/GenClangType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,8 @@ clang::CanQualType ClangTypeConverter::convert(IRGenModule &IGM, CanType type) {
705705
if (auto clangDecl = decl->getClangDecl()) {
706706
if (auto clangTypeDecl = dyn_cast<clang::TypeDecl>(clangDecl)) {
707707
auto &ctx = IGM.getClangASTContext();
708-
return ctx.getCanonicalType(ctx.getTypeDeclType(clangTypeDecl));
708+
return ctx.getCanonicalType(ctx.getTypeDeclType(clangTypeDecl))
709+
.getUnqualifiedType();
709710
} else if (auto ifaceDecl = dyn_cast<clang::ObjCInterfaceDecl>(clangDecl)) {
710711
auto &ctx = IGM.getClangASTContext();
711712
auto clangType = ctx.getObjCInterfaceType(ifaceDecl);

lib/IRGen/GenValueWitness.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,17 +419,14 @@ static Address getArgAsBuffer(IRGenFunction &IGF,
419419
return Address(arg, getFixedBufferAlignment(IGF.IGM));
420420
}
421421

422-
/// Given an abstract type --- a type possibly expressed in terms of
423-
/// unbound generic types --- return the formal type within the type's
424-
/// primary defining context.
425-
static CanType getFormalTypeInContext(CanType abstractType) {
422+
static CanType getFormalTypeInContext(CanType abstractType, DeclContext *dc) {
426423
// Map the parent of any non-generic nominal type.
427424
if (auto nominalType = dyn_cast<NominalType>(abstractType)) {
428425
// If it doesn't have a parent, or the parent doesn't need remapping,
429426
// do nothing.
430427
auto abstractParentType = nominalType.getParent();
431428
if (!abstractParentType) return abstractType;
432-
auto parentType = getFormalTypeInContext(abstractParentType);
429+
auto parentType = getFormalTypeInContext(abstractParentType, dc);
433430
if (abstractParentType == parentType) return abstractType;
434431

435432
// Otherwise, rebuild the type.
@@ -438,14 +435,24 @@ static CanType getFormalTypeInContext(CanType abstractType) {
438435

439436
// Map unbound types into their defining context.
440437
} else if (auto ugt = dyn_cast<UnboundGenericType>(abstractType)) {
441-
return ugt->getDecl()->getDeclaredTypeInContext()->getCanonicalType();
438+
return dc->mapTypeIntoContext(ugt->getDecl()->getDeclaredInterfaceType())
439+
->getCanonicalType();
442440

443441
// Everything else stays the same.
444442
} else {
445443
return abstractType;
446444
}
447445
}
448446

447+
/// Given an abstract type --- a type possibly expressed in terms of
448+
/// unbound generic types --- return the formal type within the type's
449+
/// primary defining context.
450+
static CanType getFormalTypeInContext(CanType abstractType) {
451+
if (auto nominal = abstractType.getAnyNominal())
452+
return getFormalTypeInContext(abstractType, nominal);
453+
return abstractType;
454+
}
455+
449456
/// Get the next argument and use it as the 'self' type metadata.
450457
static void getArgAsLocalSelfTypeMetadata(IRGenFunction &IGF,
451458
llvm::Function::arg_iterator &it,

lib/Parse/ParseDecl.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,19 +1820,22 @@ bool Parser::parseTypeAttributeListPresent(VarDecl::Specifier &Specifier,
18201820
SourceLoc &SpecifierLoc,
18211821
TypeAttributes &Attributes) {
18221822
Specifier = VarDecl::Specifier::Owned;
1823-
while (Tok.isAny(tok::kw_inout, tok::kw___shared, tok::kw___owned)) {
1823+
while (Tok.is(tok::kw_inout) ||
1824+
(Tok.is(tok::identifier) &&
1825+
(Tok.getRawText().equals("__shared") ||
1826+
Tok.getRawText().equals("__owned")))) {
18241827
if (SpecifierLoc.isValid()) {
18251828
diagnose(Tok, diag::parameter_specifier_repeated)
18261829
.fixItRemove(SpecifierLoc);
18271830
} else {
1828-
if (Tok.is(tok::kw___owned)) {
1829-
Specifier = VarDecl::Specifier::Owned;
1830-
} else if (Tok.is(tok::kw_inout)) {
1831+
if (Tok.is(tok::kw_inout)) {
18311832
Specifier = VarDecl::Specifier::InOut;
1832-
} else if (Tok.is(tok::kw___shared)) {
1833-
Specifier = VarDecl::Specifier::Shared;
1834-
} else {
1835-
llvm_unreachable("unhandled specifier kind?");
1833+
} else if (Tok.is(tok::identifier)) {
1834+
if (Tok.getRawText().equals("__shared")) {
1835+
Specifier = VarDecl::Specifier::Shared;
1836+
} else if (Tok.getRawText().equals("__owned")) {
1837+
Specifier = VarDecl::Specifier::Owned;
1838+
}
18361839
}
18371840
}
18381841
SpecifierLoc = consumeToken();

lib/Parse/ParsePattern.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,18 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
182182

183183
// ('inout' | 'let' | 'var' | '__shared' | '__owned')?
184184
bool hasSpecifier = false;
185-
while (Tok.isAny(tok::kw_inout, tok::kw_let, tok::kw_var,
186-
tok::kw___shared, tok::kw___owned)) {
185+
while (Tok.isAny(tok::kw_inout, tok::kw_let, tok::kw_var) ||
186+
(Tok.is(tok::identifier) &&
187+
(Tok.getRawText().equals("__shared") ||
188+
Tok.getRawText().equals("__owned")))) {
187189
if (!hasSpecifier) {
188190
if (Tok.is(tok::kw_inout)) {
189191
// This case is handled later when mapping to ParamDecls for
190192
// better fixits.
191193
param.SpecifierKind = VarDecl::Specifier::InOut;
192194
param.SpecifierLoc = consumeToken();
193-
} else if (Tok.is(tok::kw___shared)) {
195+
} else if (Tok.is(tok::identifier) &&
196+
Tok.getRawText().equals("__shared")) {
194197
// This case is handled later when mapping to ParamDecls for
195198
// better fixits.
196199
param.SpecifierKind = VarDecl::Specifier::Shared;

lib/Parse/ParseType.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,16 @@ ParserResult<TypeRepr> Parser::parseTypeSimple(Diag<> MessageID,
175175
if (Tok.is(tok::kw_inout)) {
176176
SpecifierLoc = consumeToken();
177177
TypeSpecifier = VarDecl::Specifier::InOut;
178-
} else if (Tok.is(tok::kw___shared)) {
179-
SpecifierLoc = consumeToken();
180-
TypeSpecifier = VarDecl::Specifier::Shared;
181-
} else if (Tok.is(tok::kw___owned)) {
182-
SpecifierLoc = consumeToken();
183-
TypeSpecifier = VarDecl::Specifier::Owned;
184-
178+
} else if (Tok.is(tok::identifier)) {
179+
if (Tok.getRawText().equals("__shared")) {
180+
assert(false);
181+
SpecifierLoc = consumeToken();
182+
TypeSpecifier = VarDecl::Specifier::Shared;
183+
} else if (Tok.getRawText().equals("__owned")) {
184+
assert(false);
185+
SpecifierLoc = consumeToken();
186+
TypeSpecifier = VarDecl::Specifier::Owned;
187+
}
185188
}
186189

187190
switch (Tok.getKind()) {

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,13 +2555,14 @@ namespace {
25552555
auto selected = *selectedElt;
25562556
switch (selected.choice.getKind()) {
25572557
case OverloadChoiceKind::DeclViaBridge: {
2558+
base = cs.coerceToRValue(base);
2559+
25582560
// Look through an implicitly unwrapped optional.
2559-
auto baseTy = cs.getType(base)->getRValueType();
2561+
auto baseTy = cs.getType(base);
25602562
if (auto objTy = cs.lookThroughImplicitlyUnwrappedOptionalType(baseTy)){
25612563
base = coerceImplicitlyUnwrappedOptionalToValue(base, objTy,
25622564
cs.getConstraintLocator(base));
2563-
2564-
baseTy = cs.getType(base)->getRValueType();
2565+
baseTy = objTy;
25652566
}
25662567

25672568
auto &tc = cs.getTypeChecker();

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,7 +2872,7 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
28722872
bool isImplicit;
28732873
bool isStatic;
28742874
uint8_t rawStaticSpelling, rawAccessLevel, rawAddressorKind, rawMutModifier;
2875-
bool isObjC, hasDynamicSelf, throws;
2875+
bool isObjC, hasDynamicSelf, hasForcedStaticDispatch, throws;
28762876
unsigned numParamPatterns, numNameComponentsBiased;
28772877
GenericEnvironmentID genericEnvID;
28782878
TypeID interfaceTypeID;
@@ -2885,7 +2885,8 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
28852885

28862886
decls_block::FuncLayout::readRecord(scratch, contextID, isImplicit,
28872887
isStatic, rawStaticSpelling, isObjC,
2888-
rawMutModifier, hasDynamicSelf, throws,
2888+
rawMutModifier, hasDynamicSelf,
2889+
hasForcedStaticDispatch, throws,
28892890
numParamPatterns, genericEnvID,
28902891
interfaceTypeID,
28912892
associatedDeclID, overriddenID,
@@ -3030,6 +3031,7 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
30303031
if (isImplicit)
30313032
fn->setImplicit();
30323033
fn->setDynamicSelf(hasDynamicSelf);
3034+
fn->setForcedStaticDispatch(hasForcedStaticDispatch);
30333035
fn->setNeedsNewVTableEntry(needsNewVTableEntry);
30343036

30353037
if (auto defaultArgumentResilienceExpansion = getActualResilienceExpansion(

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,6 +2991,7 @@ void Serializer::writeDecl(const Decl *D) {
29912991
uint8_t(
29922992
getStableSelfAccessKind(fn->getSelfAccessKind())),
29932993
fn->hasDynamicSelf(),
2994+
fn->hasForcedStaticDispatch(),
29942995
fn->hasThrows(),
29952996
fn->getParameterLists().size(),
29962997
addGenericEnvironmentRef(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend -typecheck %s
2+
3+
func __shared() {}
4+
5+
func __owned() {}
6+
7+
func foo() {
8+
__shared()
9+
__owned()
10+
}

test/IRGen/Inputs/clang_string_enum.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import <Foundation/Foundation.h>
2+
3+
typedef NSString * const PandaStyle NS_STRING_ENUM;
4+
5+
extern PandaStyle PandaStyleCute;

test/IRGen/clang_string_enum.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-ir %s -import-objc-header %S/Inputs/clang_string_enum.h > /dev/null
3+
4+
// REQUIRES: objc_interop
5+
6+
import Foundation
7+
8+
class PandaCub : NSObject {}
9+
10+
extension PandaCub {
11+
@objc func cuddle(_: PandaStyle) { }
12+
}

test/IRGen/nested_generics.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,16 @@ public class OuterGenericClass<T> {
7979
}
8080
}
8181
}
82+
83+
// This used to crash while emitting value witnesses.
84+
85+
public struct Fish<Water> {}
86+
87+
public protocol Wet {}
88+
89+
extension Fish where Water : Wet {
90+
public enum Fillet {
91+
case grilled
92+
case fried
93+
}
94+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Foundation
2+
3+
public class ExtremeLateBindingCounter {
4+
@objc public dynamic var counter: Int = 0
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -emit-module %S/Inputs/dynamic_witness_other_module_other.swift -emit-module-path %t
3+
4+
// RUN: %target-swift-frontend -emit-silgen %s -I %t | %FileCheck %s
5+
// RUN: %target-swift-frontend -emit-ir %s -I %t > /dev/null
6+
7+
// REQUIRES: objc_interop
8+
9+
import dynamic_witness_other_module_other
10+
11+
protocol EvenMoreExtremeLateBindingCounter {
12+
var counter: Int { get set }
13+
}
14+
15+
extension ExtremeLateBindingCounter : EvenMoreExtremeLateBindingCounter {}
16+
17+
// Make sure we emit a direct reference to the witness's materializeForSet
18+
// instead of dispatching via class_method.
19+
20+
// CHECK-LABEL: sil private [transparent] [thunk] @_T0029dynamic_witness_other_module_C025ExtremeLateBindingCounterC0a1_b1_c1_D008EvenMoreefgH0A2dEP7counterSivmTW : $@convention(witness_method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout ExtremeLateBindingCounter) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>)
21+
// CHECK: function_ref @_T0029dynamic_witness_other_module_C025ExtremeLateBindingCounterC7counterSivm : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @guaranteed ExtremeLateBindingCounter) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>)
22+
// CHECK: return

0 commit comments

Comments
 (0)