Skip to content

Fixing various regressions #12595

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
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/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ ERROR(expected_parameter_type,PointsToFirstBadToken,
ERROR(expected_parameter_name,PointsToFirstBadToken,
"expected parameter name followed by ':'", ())
ERROR(expected_parameter_colon,PointsToFirstBadToken,
"expected ':' following argumant label and parameter name", ())
"expected ':' following argument label and parameter name", ())
ERROR(missing_parameter_type,PointsToFirstBadToken,
"parameter requires an explicit type", ())
ERROR(multiple_parameter_ellipsis,none,
Expand Down
16 changes: 4 additions & 12 deletions include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "swift/Basic/OptionSet.h"
#include "swift/Basic/SourceLoc.h"
#include "swift/Basic/STLExtras.h"
#include "swift/Parse/Token.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SetVector.h"
Expand Down Expand Up @@ -72,6 +71,7 @@ namespace swift {
class ProtocolDecl;
struct PrintOptions;
class ReferencedNameTracker;
class Token;
class TupleType;
class Type;
class TypeRefinementContext;
Expand Down Expand Up @@ -1076,19 +1076,11 @@ class SourceFile final : public FileUnit {
out << str << '\n';
}

std::vector<Token> &getTokenVector() {
assert(shouldKeepTokens() && "Disabled");
return *AllCorrectedTokens;
}
std::vector<Token> &getTokenVector();

ArrayRef<Token> getAllTokens() const {
assert(shouldKeepTokens() && "Disabled");
return *AllCorrectedTokens;
}
ArrayRef<Token> getAllTokens() const;

bool shouldKeepTokens() const {
return (bool)AllCorrectedTokens;
}
bool shouldKeepTokens() const;

syntax::SourceFileSyntax getSyntaxRoot() const;

Expand Down
5 changes: 4 additions & 1 deletion include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,10 @@ class Parser {
bool parseTypeAttributeList(VarDecl::Specifier &Specifier,
SourceLoc &SpecifierLoc,
TypeAttributes &Attributes) {
if (Tok.isAny(tok::at_sign, tok::kw_inout, tok::kw___shared, tok::kw___owned))
if (Tok.isAny(tok::at_sign, tok::kw_inout) ||
(Tok.is(tok::identifier) &&
(Tok.getRawText().equals("__shared") ||
Tok.getRawText().equals("__owned"))))
return parseTypeAttributeListPresent(Specifier, SpecifierLoc, Attributes);
return false;
}
Expand Down
14 changes: 9 additions & 5 deletions include/swift/Parse/Token.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,17 @@ class Token {
/// used
bool canBeArgumentLabel() const {
// Identifiers, escaped identifiers, and '_' can be argument labels.
if (is(tok::identifier) || isEscapedIdentifier() || is(tok::kw__))
if (is(tok::identifier) || isEscapedIdentifier() || is(tok::kw__)) {
// ... except for '__shared' and '__owned'.
if (getRawText().equals("__shared") ||
getRawText().equals("__owned"))
return false;

return true;
}

// 'let', 'var', 'inout', '__shared', and '__owned'
// cannot be argument labels.
if (isAny(tok::kw_let, tok::kw_var, tok::kw_inout,
tok::kw___owned, tok::kw___shared))
// 'let', 'var', and 'inout' cannot be argument labels.
if (isAny(tok::kw_let, tok::kw_var, tok::kw_inout))
return false;

// All other keywords can be argument labels.
Expand Down
3 changes: 2 additions & 1 deletion include/swift/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
/// in source control, you should also update the comment to briefly
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
const uint16_t VERSION_MINOR = 373; // Last change: destructure
const uint16_t VERSION_MINOR = 374; // Last change: has forced static dispatch

using DeclID = PointerEmbeddedInt<unsigned, 31>;
using DeclIDField = BCFixed<31>;
Expand Down Expand Up @@ -955,6 +955,7 @@ namespace decls_block {
BCFixed<1>, // explicitly objc?
SelfAccessKindField, // self access kind
BCFixed<1>, // has dynamic self?
BCFixed<1>, // has forced static dispatch?
BCFixed<1>, // throws?
BCVBR<5>, // number of parameter patterns
GenericEnvironmentIDField, // generic environment
Expand Down
2 changes: 0 additions & 2 deletions include/swift/Syntax/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ DECL_KEYWORD(struct)
DECL_KEYWORD(subscript)
DECL_KEYWORD(typealias)
DECL_KEYWORD(var)
DECL_KEYWORD(__shared)
DECL_KEYWORD(__owned)

DECL_KEYWORD(fileprivate)
DECL_KEYWORD(internal)
Expand Down
15 changes: 15 additions & 0 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "swift/AST/ProtocolConformance.h"
#include "swift/Basic/Compiler.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Parse/Token.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this better? Just fewer includes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, editing Token.h does not trigger recompilation of ~400 source files anymore.

#include "swift/Syntax/SyntaxNodes.h"
#include "swift/Syntax/SyntaxParsingContext.h"
#include "clang/Basic/Module.h"
Expand Down Expand Up @@ -1364,6 +1365,20 @@ SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,

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

std::vector<Token> &SourceFile::getTokenVector() {
assert(shouldKeepTokens() && "Disabled");
return *AllCorrectedTokens;
}

ArrayRef<Token> SourceFile::getAllTokens() const {
assert(shouldKeepTokens() && "Disabled");
return *AllCorrectedTokens;
}

bool SourceFile::shouldKeepTokens() const {
return (bool)AllCorrectedTokens;
}

bool FileUnit::walk(ASTWalker &walker) {
SmallVector<Decl *, 64> Decls;
getTopLevelDecls(Decls);
Expand Down
3 changes: 2 additions & 1 deletion lib/IRGen/GenClangType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,8 @@ clang::CanQualType ClangTypeConverter::convert(IRGenModule &IGM, CanType type) {
if (auto clangDecl = decl->getClangDecl()) {
if (auto clangTypeDecl = dyn_cast<clang::TypeDecl>(clangDecl)) {
auto &ctx = IGM.getClangASTContext();
return ctx.getCanonicalType(ctx.getTypeDeclType(clangTypeDecl));
return ctx.getCanonicalType(ctx.getTypeDeclType(clangTypeDecl))
.getUnqualifiedType();
} else if (auto ifaceDecl = dyn_cast<clang::ObjCInterfaceDecl>(clangDecl)) {
auto &ctx = IGM.getClangASTContext();
auto clangType = ctx.getObjCInterfaceType(ifaceDecl);
Expand Down
19 changes: 13 additions & 6 deletions lib/IRGen/GenValueWitness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,17 +419,14 @@ static Address getArgAsBuffer(IRGenFunction &IGF,
return Address(arg, getFixedBufferAlignment(IGF.IGM));
}

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

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

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

// Everything else stays the same.
} else {
return abstractType;
}
}

/// Given an abstract type --- a type possibly expressed in terms of
/// unbound generic types --- return the formal type within the type's
/// primary defining context.
static CanType getFormalTypeInContext(CanType abstractType) {
if (auto nominal = abstractType.getAnyNominal())
return getFormalTypeInContext(abstractType, nominal);
return abstractType;
}

/// Get the next argument and use it as the 'self' type metadata.
static void getArgAsLocalSelfTypeMetadata(IRGenFunction &IGF,
llvm::Function::arg_iterator &it,
Expand Down
19 changes: 11 additions & 8 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1820,19 +1820,22 @@ bool Parser::parseTypeAttributeListPresent(VarDecl::Specifier &Specifier,
SourceLoc &SpecifierLoc,
TypeAttributes &Attributes) {
Specifier = VarDecl::Specifier::Owned;
while (Tok.isAny(tok::kw_inout, tok::kw___shared, tok::kw___owned)) {
while (Tok.is(tok::kw_inout) ||
(Tok.is(tok::identifier) &&
(Tok.getRawText().equals("__shared") ||
Tok.getRawText().equals("__owned")))) {
if (SpecifierLoc.isValid()) {
diagnose(Tok, diag::parameter_specifier_repeated)
.fixItRemove(SpecifierLoc);
} else {
if (Tok.is(tok::kw___owned)) {
Specifier = VarDecl::Specifier::Owned;
} else if (Tok.is(tok::kw_inout)) {
if (Tok.is(tok::kw_inout)) {
Specifier = VarDecl::Specifier::InOut;
} else if (Tok.is(tok::kw___shared)) {
Specifier = VarDecl::Specifier::Shared;
} else {
llvm_unreachable("unhandled specifier kind?");
} else if (Tok.is(tok::identifier)) {
if (Tok.getRawText().equals("__shared")) {
Specifier = VarDecl::Specifier::Shared;
} else if (Tok.getRawText().equals("__owned")) {
Specifier = VarDecl::Specifier::Owned;
}
}
}
SpecifierLoc = consumeToken();
Expand Down
9 changes: 6 additions & 3 deletions lib/Parse/ParsePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,18 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,

// ('inout' | 'let' | 'var' | '__shared' | '__owned')?
bool hasSpecifier = false;
while (Tok.isAny(tok::kw_inout, tok::kw_let, tok::kw_var,
tok::kw___shared, tok::kw___owned)) {
while (Tok.isAny(tok::kw_inout, tok::kw_let, tok::kw_var) ||
(Tok.is(tok::identifier) &&
(Tok.getRawText().equals("__shared") ||
Tok.getRawText().equals("__owned")))) {
if (!hasSpecifier) {
if (Tok.is(tok::kw_inout)) {
// This case is handled later when mapping to ParamDecls for
// better fixits.
param.SpecifierKind = VarDecl::Specifier::InOut;
param.SpecifierLoc = consumeToken();
} else if (Tok.is(tok::kw___shared)) {
} else if (Tok.is(tok::identifier) &&
Tok.getRawText().equals("__shared")) {
// This case is handled later when mapping to ParamDecls for
// better fixits.
param.SpecifierKind = VarDecl::Specifier::Shared;
Expand Down
17 changes: 10 additions & 7 deletions lib/Parse/ParseType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,16 @@ ParserResult<TypeRepr> Parser::parseTypeSimple(Diag<> MessageID,
if (Tok.is(tok::kw_inout)) {
SpecifierLoc = consumeToken();
TypeSpecifier = VarDecl::Specifier::InOut;
} else if (Tok.is(tok::kw___shared)) {
SpecifierLoc = consumeToken();
TypeSpecifier = VarDecl::Specifier::Shared;
} else if (Tok.is(tok::kw___owned)) {
SpecifierLoc = consumeToken();
TypeSpecifier = VarDecl::Specifier::Owned;

} else if (Tok.is(tok::identifier)) {
if (Tok.getRawText().equals("__shared")) {
assert(false);
SpecifierLoc = consumeToken();
TypeSpecifier = VarDecl::Specifier::Shared;
} else if (Tok.getRawText().equals("__owned")) {
assert(false);
SpecifierLoc = consumeToken();
TypeSpecifier = VarDecl::Specifier::Owned;
}
}

switch (Tok.getKind()) {
Expand Down
7 changes: 4 additions & 3 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2555,13 +2555,14 @@ namespace {
auto selected = *selectedElt;
switch (selected.choice.getKind()) {
case OverloadChoiceKind::DeclViaBridge: {
base = cs.coerceToRValue(base);

// Look through an implicitly unwrapped optional.
auto baseTy = cs.getType(base)->getRValueType();
auto baseTy = cs.getType(base);
if (auto objTy = cs.lookThroughImplicitlyUnwrappedOptionalType(baseTy)){
base = coerceImplicitlyUnwrappedOptionalToValue(base, objTy,
cs.getConstraintLocator(base));

baseTy = cs.getType(base)->getRValueType();
baseTy = objTy;
}

auto &tc = cs.getTypeChecker();
Expand Down
6 changes: 4 additions & 2 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2872,7 +2872,7 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
bool isImplicit;
bool isStatic;
uint8_t rawStaticSpelling, rawAccessLevel, rawAddressorKind, rawMutModifier;
bool isObjC, hasDynamicSelf, throws;
bool isObjC, hasDynamicSelf, hasForcedStaticDispatch, throws;
unsigned numParamPatterns, numNameComponentsBiased;
GenericEnvironmentID genericEnvID;
TypeID interfaceTypeID;
Expand All @@ -2885,7 +2885,8 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {

decls_block::FuncLayout::readRecord(scratch, contextID, isImplicit,
isStatic, rawStaticSpelling, isObjC,
rawMutModifier, hasDynamicSelf, throws,
rawMutModifier, hasDynamicSelf,
hasForcedStaticDispatch, throws,
numParamPatterns, genericEnvID,
interfaceTypeID,
associatedDeclID, overriddenID,
Expand Down Expand Up @@ -3030,6 +3031,7 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
if (isImplicit)
fn->setImplicit();
fn->setDynamicSelf(hasDynamicSelf);
fn->setForcedStaticDispatch(hasForcedStaticDispatch);
fn->setNeedsNewVTableEntry(needsNewVTableEntry);

if (auto defaultArgumentResilienceExpansion = getActualResilienceExpansion(
Expand Down
1 change: 1 addition & 0 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2991,6 +2991,7 @@ void Serializer::writeDecl(const Decl *D) {
uint8_t(
getStableSelfAccessKind(fn->getSelfAccessKind())),
fn->hasDynamicSelf(),
fn->hasForcedStaticDispatch(),
fn->hasThrows(),
fn->getParameterLists().size(),
addGenericEnvironmentRef(
Expand Down
10 changes: 10 additions & 0 deletions test/Compatibility/shared_owned_identifiers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %target-swift-frontend -typecheck %s

func __shared() {}

func __owned() {}

func foo() {
__shared()
__owned()
}
5 changes: 5 additions & 0 deletions test/IRGen/Inputs/clang_string_enum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <Foundation/Foundation.h>

typedef NSString * const PandaStyle NS_STRING_ENUM;

extern PandaStyle PandaStyleCute;
12 changes: 12 additions & 0 deletions test/IRGen/clang_string_enum.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-ir %s -import-objc-header %S/Inputs/clang_string_enum.h > /dev/null

// REQUIRES: objc_interop

import Foundation

class PandaCub : NSObject {}

extension PandaCub {
@objc func cuddle(_: PandaStyle) { }
}
13 changes: 13 additions & 0 deletions test/IRGen/nested_generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,16 @@ public class OuterGenericClass<T> {
}
}
}

// This used to crash while emitting value witnesses.

public struct Fish<Water> {}

public protocol Wet {}

extension Fish where Water : Wet {
public enum Fillet {
case grilled
case fried
}
}
5 changes: 5 additions & 0 deletions test/SILGen/Inputs/dynamic_witness_other_module_other.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public class ExtremeLateBindingCounter {
@objc public dynamic var counter: Int = 0
}
22 changes: 22 additions & 0 deletions test/SILGen/dynamic_witness_other_module.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -emit-module %S/Inputs/dynamic_witness_other_module_other.swift -emit-module-path %t

// RUN: %target-swift-frontend -emit-silgen %s -I %t | %FileCheck %s
// RUN: %target-swift-frontend -emit-ir %s -I %t > /dev/null

// REQUIRES: objc_interop

import dynamic_witness_other_module_other

protocol EvenMoreExtremeLateBindingCounter {
var counter: Int { get set }
}

extension ExtremeLateBindingCounter : EvenMoreExtremeLateBindingCounter {}

// Make sure we emit a direct reference to the witness's materializeForSet
// instead of dispatching via class_method.

// 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>)
// CHECK: function_ref @_T0029dynamic_witness_other_module_C025ExtremeLateBindingCounterC7counterSivm : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @guaranteed ExtremeLateBindingCounter) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>)
// CHECK: return
Loading