Skip to content

Commit af2aca0

Browse files
authored
Merge pull request #10092 from xedin/pointer-conversions
2 parents 8fbee40 + 3559047 commit af2aca0

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,14 @@ void ConstraintSystem::increaseScore(ScoreKind kind, unsigned value) {
7070
case SK_ValueToOptional:
7171
log << "value to optional";
7272
break;
73-
74-
case SK_ArrayPointerConversion:
75-
log << "array-to-pointer conversion";
76-
break;
77-
case SK_ScalarPointerConversion:
78-
log << "scalar-to-pointer conversion";
79-
break;
8073
case SK_EmptyExistentialConversion:
8174
log << "empty-existential conversion";
8275
break;
8376
case SK_KeyPathSubscript:
8477
log << "key path subscript";
8578
break;
86-
87-
case SK_StringToPointerConversion:
88-
log << "string-to-pointer conversion";
79+
case SK_ValueToPointerConversion:
80+
log << "value-to-pointer conversion";
8981
break;
9082
}
9183
log << ")\n";

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,15 +2080,15 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
20802080
// Favor an UnsafeMutablePointer-to-UnsafeMutablePointer
20812081
// conversion.
20822082
if (type1PointerKind != pointerKind)
2083-
increaseScore(ScoreKind::SK_ScalarPointerConversion);
2083+
increaseScore(ScoreKind::SK_ValueToPointerConversion);
20842084
conversionsOrFixes.push_back(
20852085
ConversionRestrictionKind::PointerToPointer);
20862086
}
20872087
// UnsafeMutableRawPointer -> UnsafeRawPointer
20882088
else if (type1PointerKind == PTK_UnsafeMutableRawPointer &&
20892089
pointerKind == PTK_UnsafeRawPointer) {
20902090
if (type1PointerKind != pointerKind)
2091-
increaseScore(ScoreKind::SK_ScalarPointerConversion);
2091+
increaseScore(ScoreKind::SK_ValueToPointerConversion);
20922092
conversionsOrFixes.push_back(
20932093
ConversionRestrictionKind::PointerToPointer);
20942094
}
@@ -4379,6 +4379,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
43794379
auto baseType1 = getFixedTypeRecursive(*isArrayType(obj1), false, false);
43804380
auto baseType2 = getBaseTypeForPointer(*this, t2);
43814381

4382+
increaseScore(ScoreKind::SK_ValueToPointerConversion);
43824383
return matchTypes(baseType1, baseType2,
43834384
ConstraintKind::BindToPointerType,
43844385
subflags, locator);
@@ -4398,7 +4399,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
43984399
// If we haven't resolved the element type, generate constraints.
43994400
if (baseType2->isTypeVariableOrMember()) {
44004401
if (flags.contains(TMF_GenerateConstraints)) {
4401-
increaseScore(SK_StringToPointerConversion);
4402+
increaseScore(ScoreKind::SK_ValueToPointerConversion);
44024403

44034404
auto int8Con = Constraint::create(*this, ConstraintKind::Bind,
44044405
baseType2, TC.getInt8Type(DC),
@@ -4422,7 +4423,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
44224423
return SolutionKind::Error;
44234424
}
44244425

4425-
increaseScore(SK_StringToPointerConversion);
4426+
increaseScore(ScoreKind::SK_ValueToPointerConversion);
44264427
return SolutionKind::Solved;
44274428
}
44284429

@@ -4437,6 +4438,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
44374438

44384439
// Set up the disjunction for the array or scalar cases.
44394440

4441+
increaseScore(ScoreKind::SK_ValueToPointerConversion);
44404442
return matchTypes(baseType1, baseType2,
44414443
ConstraintKind::BindToPointerType,
44424444
subflags, locator);

lib/Sema/ConstraintSystem.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,18 +408,14 @@ enum ScoreKind {
408408
SK_CollectionUpcastConversion,
409409
/// A value-to-optional conversion.
410410
SK_ValueToOptional,
411-
/// A conversion from an inout to a pointer of matching element type.
412-
SK_ScalarPointerConversion,
413-
/// A conversion from an array to a pointer of matching element type.
414-
SK_ArrayPointerConversion,
415411
/// A conversion to an empty existential type ('Any' or '{}').
416412
SK_EmptyExistentialConversion,
417413
/// A key path application subscript.
418414
SK_KeyPathSubscript,
419-
// A conversion from a string to a pointer.
420-
SK_StringToPointerConversion,
415+
/// A conversion from a string, array, or inout to a pointer.
416+
SK_ValueToPointerConversion,
421417

422-
SK_LastScoreKind = SK_StringToPointerConversion,
418+
SK_LastScoreKind = SK_ValueToPointerConversion,
423419
};
424420

425421
/// The number of score kinds.

0 commit comments

Comments
 (0)