Skip to content

Commit 45c3a33

Browse files
authored
---
yaml --- r: 340670 b: refs/heads/rxwei-patch-1 c: a516de5 h: refs/heads/master
1 parent 25bde6d commit 45c3a33

File tree

62 files changed

+786
-303
lines changed

Some content is hidden

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

62 files changed

+786
-303
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: 0150ae52ca3787ea16e7f3d6e299182f51d7e3dd
1018+
refs/heads/rxwei-patch-1: a516de58bda9f390b1d4ccc73afe1380b4fa3438
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ ERROR(cannot_convert_closure_result_protocol,none,
393393
(Type, Type))
394394
ERROR(cannot_convert_closure_result_nil,none,
395395
"'nil' is not compatible with closure result type %0", (Type))
396+
ERROR(cannot_convert_parent_type,none,
397+
"cannot convert parent type %0 to expected type %1",
398+
(Type, Type))
399+
400+
NOTE(generic_argument_mismatch,none,
401+
"arguments to generic parameter %0 (%1 and %2) are expected to be equal",
402+
(Identifier, Type, Type))
396403

397404
ERROR(destructor_not_accessible,none,
398405
"deinitializers cannot be accessed", ())

branches/rxwei-patch-1/include/swift/AST/PrintOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ struct PrintOptions {
494494
/// consistent and well-formed.
495495
///
496496
/// \see swift::emitParseableInterface
497-
static PrintOptions printParseableInterfaceFile();
497+
static PrintOptions printParseableInterfaceFile(bool preferTypeRepr);
498498

499499
static PrintOptions printModuleInterface();
500500
static PrintOptions printTypeInterface(Type T);

branches/rxwei-patch-1/include/swift/Frontend/ParseableInterfaceSupport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class ModuleDecl;
2727

2828
/// Options for controlling the generation of the .swiftinterface output.
2929
struct ParseableInterfaceOptions {
30+
/// Should we prefer printing TypeReprs when writing out types in a module
31+
/// interface, or should we fully-qualify them?
32+
bool PreserveTypesAsWritten = false;
33+
3034
/// Copy of all the command-line flags passed at .swiftinterface
3135
/// generation time, re-applied to CompilerInvocation when reading
3236
/// back .swiftinterface and reconstructing .swiftmodule.

branches/rxwei-patch-1/include/swift/Option/FrontendOptions.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ def build_module_from_parseable_interface :
535535
Alias<compile_module_from_interface>,
536536
ModeOpt;
537537

538+
def module_interface_preserve_types_as_written :
539+
Flag<["-"], "module-interface-preserve-types-as-written">,
540+
HelpText<"When emitting a module interface, preserve types as they were "
541+
"written in the source">;
542+
538543
def prebuilt_module_cache_path :
539544
Separate<["-"], "prebuilt-module-cache-path">,
540545
HelpText<"Directory of prebuilt modules for loading module interfaces">;

branches/rxwei-patch-1/lib/AST/ASTPrinter.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static bool contributesToParentTypeStorage(const AbstractStorageDecl *ASD) {
9494
return !ND->isResilient() && ASD->hasStorage() && !ASD->isStatic();
9595
}
9696

97-
PrintOptions PrintOptions::printParseableInterfaceFile() {
97+
PrintOptions PrintOptions::printParseableInterfaceFile(bool preferTypeRepr) {
9898
PrintOptions result;
9999
result.PrintLongAttrsOnSeparateLines = true;
100100
result.TypeDefinitions = true;
@@ -110,6 +110,7 @@ PrintOptions PrintOptions::printParseableInterfaceFile() {
110110
result.EnumRawValues = EnumRawValueMode::PrintObjCOnly;
111111
result.OpaqueReturnTypePrinting =
112112
OpaqueReturnTypePrintingMode::StableReference;
113+
result.PreferTypeRepr = preferTypeRepr;
113114

114115
// We should print __consuming, __owned, etc for the module interface file.
115116
result.SkipUnderscoredKeywords = false;
@@ -1004,7 +1005,18 @@ void PrintAST::printAttributes(const Decl *D) {
10041005
void PrintAST::printTypedPattern(const TypedPattern *TP) {
10051006
printPattern(TP->getSubPattern());
10061007
Printer << ": ";
1007-
printTypeLoc(TP->getTypeLoc());
1008+
1009+
// Make sure to check if the underlying var decl is an implicitly unwrapped
1010+
// optional.
1011+
bool isIUO = false;
1012+
if (auto *named = dyn_cast<NamedPattern>(TP->getSubPattern()))
1013+
if (auto decl = named->getDecl())
1014+
isIUO = decl->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
1015+
1016+
if (isIUO)
1017+
printTypeLocForImplicitlyUnwrappedOptional(TP->getTypeLoc());
1018+
else
1019+
printTypeLoc(TP->getTypeLoc());
10081020
}
10091021

10101022
/// Determines if we are required to print the name of a property declaration,
@@ -2530,6 +2542,14 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
25302542
tyLoc = TypeLoc::withoutLoc(decl->getInterfaceType());
25312543

25322544
Printer.printDeclResultTypePre(decl, tyLoc);
2545+
2546+
// HACK: When printing result types for vars with opaque result types,
2547+
// always print them using the `some` keyword instead of printing
2548+
// the full stable reference.
2549+
llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
2550+
x(Options.OpaqueReturnTypePrinting,
2551+
PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
2552+
25332553
if (decl->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>())
25342554
printTypeLocForImplicitlyUnwrappedOptional(tyLoc);
25352555
else
@@ -2805,6 +2825,14 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
28052825

28062826
Printer.printDeclResultTypePre(decl, ResultTyLoc);
28072827
Printer.callPrintStructurePre(PrintStructureKind::FunctionReturnType);
2828+
2829+
// HACK: When printing result types for funcs with opaque result types,
2830+
// always print them using the `some` keyword instead of printing
2831+
// the full stable reference.
2832+
llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
2833+
x(Options.OpaqueReturnTypePrinting,
2834+
PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
2835+
28082836
if (decl->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>())
28092837
printTypeLocForImplicitlyUnwrappedOptional(ResultTyLoc);
28102838
else
@@ -2947,6 +2975,14 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
29472975
Printer.callPrintStructurePre(PrintStructureKind::FunctionReturnType);
29482976
if (!elementTy.getTypeRepr())
29492977
elementTy = TypeLoc::withoutLoc(decl->getElementInterfaceType());
2978+
2979+
// HACK: When printing result types for subscripts with opaque result types,
2980+
// always print them using the `some` keyword instead of printing
2981+
// the full stable reference.
2982+
llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
2983+
x(Options.OpaqueReturnTypePrinting,
2984+
PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
2985+
29502986
if (decl->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>())
29512987
printTypeLocForImplicitlyUnwrappedOptional(elementTy);
29522988
else

branches/rxwei-patch-1/lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,17 +2046,8 @@ TypeDecl *EquivalenceClass::lookupNestedType(
20462046
continue;
20472047
}
20482048

2049-
// If this is another type declaration, determine whether we should
2050-
// record it.
2049+
// If this is another type declaration, record it.
20512050
if (auto type = dyn_cast<TypeDecl>(member)) {
2052-
// FIXME: Filter out type declarations that aren't in the same
2053-
// module as the protocol itself. This is an unprincipled hack, but
2054-
// provides consistent lookup semantics for the generic signature
2055-
// builder in all contents.
2056-
if (type->getDeclContext()->getParentModule()
2057-
!= proto->getParentModule())
2058-
continue;
2059-
20602051
concreteDecls.push_back(type);
20612052
continue;
20622053
}

branches/rxwei-patch-1/lib/Driver/Driver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,14 +1319,14 @@ static bool isSDKTooOld(StringRef sdkPath, llvm::VersionTuple minVersion,
13191319
/// the given target.
13201320
static bool isSDKTooOld(StringRef sdkPath, const llvm::Triple &target) {
13211321
if (target.isMacOSX()) {
1322-
return isSDKTooOld(sdkPath, llvm::VersionTuple(10, 14), "OSX");
1322+
return isSDKTooOld(sdkPath, llvm::VersionTuple(10, 15), "OSX");
13231323

13241324
} else if (target.isiOS()) {
13251325
// Includes both iOS and TVOS.
1326-
return isSDKTooOld(sdkPath, llvm::VersionTuple(12, 0), "Simulator", "OS");
1326+
return isSDKTooOld(sdkPath, llvm::VersionTuple(13, 0), "Simulator", "OS");
13271327

13281328
} else if (target.isWatchOS()) {
1329-
return isSDKTooOld(sdkPath, llvm::VersionTuple(5, 0), "Simulator", "OS");
1329+
return isSDKTooOld(sdkPath, llvm::VersionTuple(6, 0), "Simulator", "OS");
13301330

13311331
} else {
13321332
return false;

branches/rxwei-patch-1/lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ static void PrintArg(raw_ostream &OS, const char *Arg, StringRef TempDir) {
197197
OS << '"';
198198
}
199199

200+
static void ParseParseableInterfaceArgs(ParseableInterfaceOptions &Opts,
201+
ArgList &Args) {
202+
using namespace options;
203+
204+
Opts.PreserveTypesAsWritten |=
205+
Args.hasArg(OPT_module_interface_preserve_types_as_written);
206+
}
207+
200208
/// Save a copy of any flags marked as ModuleInterfaceOption, if running
201209
/// in a mode that is going to emit a .swiftinterface file.
202210
static void SaveParseableInterfaceArgs(ParseableInterfaceOptions &Opts,
@@ -1306,6 +1314,7 @@ bool CompilerInvocation::parseArgs(
13061314
return true;
13071315
}
13081316

1317+
ParseParseableInterfaceArgs(ParseableInterfaceOpts, ParsedArgs);
13091318
SaveParseableInterfaceArgs(ParseableInterfaceOpts, FrontendOpts,
13101319
ParsedArgs, Diags);
13111320

branches/rxwei-patch-1/lib/Frontend/ParseableInterfaceSupport.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ bool swift::emitParseableInterface(raw_ostream &out,
411411
printToolVersionAndFlagsComment(out, Opts, M);
412412
printImports(out, M);
413413

414-
const PrintOptions printOptions = PrintOptions::printParseableInterfaceFile();
414+
const PrintOptions printOptions = PrintOptions::printParseableInterfaceFile(
415+
Opts.PreserveTypesAsWritten);
415416
InheritedProtocolCollector::PerTypeMap inheritedProtocolMap;
416417

417418
SmallVector<Decl *, 16> topLevelDecls;

branches/rxwei-patch-1/lib/Sema/CSDiagnostics.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,117 @@ bool MissingConformanceFailure::diagnoseAsError() {
384384
return RequirementFailure::diagnoseAsError();
385385
}
386386

387+
Optional<Diag<Type, Type>> GenericArgumentsMismatchFailure::getDiagnosticFor(
388+
ContextualTypePurpose context) {
389+
switch (context) {
390+
case CTP_Initialization:
391+
case CTP_AssignSource:
392+
return diag::cannot_convert_assign;
393+
case CTP_ReturnStmt:
394+
case CTP_ReturnSingleExpr:
395+
return diag::cannot_convert_to_return_type;
396+
case CTP_DefaultParameter:
397+
return diag::cannot_convert_default_arg_value;
398+
case CTP_YieldByValue:
399+
return diag::cannot_convert_yield_value;
400+
case CTP_CallArgument:
401+
return diag::cannot_convert_argument_value;
402+
case CTP_ClosureResult:
403+
return diag::cannot_convert_closure_result;
404+
case CTP_ArrayElement:
405+
return diag::cannot_convert_array_element;
406+
// TODO(diagnostics): Make dictionary related diagnostics take prescedence
407+
// over CSDiag. Currently these won't ever be produced.
408+
case CTP_DictionaryKey:
409+
return diag::cannot_convert_dict_key;
410+
case CTP_DictionaryValue:
411+
return diag::cannot_convert_dict_value;
412+
case CTP_CoerceOperand:
413+
return diag::cannot_convert_coerce;
414+
case CTP_SubscriptAssignSource:
415+
return diag::cannot_convert_subscript_assign;
416+
417+
case CTP_ThrowStmt:
418+
case CTP_Unused:
419+
case CTP_CannotFail:
420+
case CTP_YieldByReference:
421+
case CTP_CalleeResult:
422+
case CTP_EnumCaseRawValue:
423+
break;
424+
}
425+
return None;
426+
}
427+
428+
void GenericArgumentsMismatchFailure::emitNoteForMismatch(int position) {
429+
auto genericTypeDecl = getActual()->getCanonicalType()->getAnyGeneric();
430+
auto param = genericTypeDecl->getGenericParams()->getParams()[position];
431+
432+
auto lhs = resolveType(getActual()->getGenericArgs()[position])
433+
->reconstituteSugar(/*recursive=*/false);
434+
auto rhs = resolveType(getRequired()->getGenericArgs()[position])
435+
->reconstituteSugar(/*recursive=*/false);
436+
437+
auto noteLocation = param->getLoc();
438+
439+
if (!noteLocation.isValid()) {
440+
noteLocation = getAnchor()->getLoc();
441+
}
442+
443+
emitDiagnostic(noteLocation, diag::generic_argument_mismatch,
444+
param->getName(), lhs, rhs);
445+
}
446+
447+
bool GenericArgumentsMismatchFailure::diagnoseAsError() {
448+
auto *anchor = getAnchor();
449+
auto path = getLocator()->getPath();
450+
451+
Optional<Diag<Type, Type>> diagnostic;
452+
if (path.empty()) {
453+
assert(isa<AssignExpr>(anchor));
454+
diagnostic = getDiagnosticFor(CTP_AssignSource);
455+
} else {
456+
const auto &last = path.back();
457+
switch (last.getKind()) {
458+
case ConstraintLocator::ContextualType: {
459+
auto purpose = getConstraintSystem().getContextualTypePurpose();
460+
assert(purpose != CTP_Unused);
461+
diagnostic = getDiagnosticFor(purpose);
462+
break;
463+
}
464+
465+
case ConstraintLocator::AutoclosureResult:
466+
case ConstraintLocator::ApplyArgToParam:
467+
case ConstraintLocator::ApplyArgument: {
468+
diagnostic = diag::cannot_convert_argument_value;
469+
break;
470+
}
471+
472+
case ConstraintLocator::ParentType: {
473+
diagnostic = diag::cannot_convert_parent_type;
474+
break;
475+
}
476+
477+
case ConstraintLocator::ClosureResult: {
478+
diagnostic = diag::cannot_convert_closure_result;
479+
break;
480+
}
481+
482+
default:
483+
break;
484+
}
485+
}
486+
487+
if (!diagnostic)
488+
return false;
489+
490+
emitDiagnostic(
491+
getAnchor()->getLoc(), *diagnostic,
492+
resolveType(getActual())->reconstituteSugar(/*recursive=*/false),
493+
resolveType(getRequired())->reconstituteSugar(/*recursive=*/false));
494+
emitNotesForMismatches();
495+
return true;
496+
}
497+
387498
bool LabelingFailure::diagnoseAsError() {
388499
auto &cs = getConstraintSystem();
389500
auto *anchor = getRawAnchor();

branches/rxwei-patch-1/lib/Sema/CSDiagnostics.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class FailureDiagnostic {
6969
bool diagnose(bool asNote = false);
7070

7171
/// Try to produce an error diagnostic for the problem at hand.
72+
///
73+
/// \returns true If anything was diagnosed, false otherwise.
7274
virtual bool diagnoseAsError() = 0;
7375

7476
/// Instead of producing an error diagnostic, attempt to
@@ -359,6 +361,45 @@ class MissingConformanceFailure final : public RequirementFailure {
359361
}
360362
};
361363

364+
/// Diagnostics for mismatched generic arguments e.g
365+
/// ```swift
366+
/// struct F<G> {}
367+
/// let _:F<Int> = F<Bool>()
368+
/// ```
369+
class GenericArgumentsMismatchFailure final : public FailureDiagnostic {
370+
BoundGenericType *Actual;
371+
BoundGenericType *Required;
372+
ArrayRef<unsigned> Mismatches;
373+
374+
public:
375+
GenericArgumentsMismatchFailure(Expr *expr, ConstraintSystem &cs,
376+
BoundGenericType *actual,
377+
BoundGenericType *required,
378+
ArrayRef<unsigned> mismatches,
379+
ConstraintLocator *locator)
380+
: FailureDiagnostic(expr, cs, locator), Actual(actual),
381+
Required(required), Mismatches(mismatches) {}
382+
383+
bool diagnoseAsError() override;
384+
385+
private:
386+
void emitNotesForMismatches() {
387+
for (unsigned position : Mismatches) {
388+
emitNoteForMismatch(position);
389+
}
390+
}
391+
392+
void emitNoteForMismatch(int mismatchPosition);
393+
394+
Optional<Diag<Type, Type>> getDiagnosticFor(ContextualTypePurpose context);
395+
396+
/// The actual type being used.
397+
BoundGenericType *getActual() const { return Actual; }
398+
399+
/// The type needed by the generic requirement.
400+
BoundGenericType *getRequired() const { return Required; }
401+
};
402+
362403
/// Diagnose failures related to same-type generic requirements, e.g.
363404
/// ```swift
364405
/// protocol P {

0 commit comments

Comments
 (0)