@@ -745,34 +745,34 @@ static Expr* integerLiteralExpr(ASTContext &C, int64_t value) {
745
745
return integerExpr;
746
746
}
747
747
748
- // / Returns a new assignment expression that mixes the hash value of an
748
+ // / Returns a new assignment expression that combines the hash value of an
749
749
// / expression into a variable.
750
750
// / \p C The AST context.
751
- // / \p resultVar The variable into which the hash value will be mixed .
752
- // / \p exprToHash The expression whose hash value should be mixed in .
753
- // / \return The expression that mixes the hash value into the result variable.
754
- static Expr* mixInHashExpr_hashValue (ASTContext &C,
755
- VarDecl* resultVar,
756
- Expr *exprToHash) {
751
+ // / \p resultVar The variable into which the hash value will be combined .
752
+ // / \p exprToHash The expression whose hash value should be combined .
753
+ // / \return The expression that combines the hash value into the variable.
754
+ static Expr* combineHashValuesAssignmentExpr (ASTContext &C,
755
+ VarDecl* resultVar,
756
+ Expr *exprToHash) {
757
757
// <exprToHash>.hashValue
758
758
auto hashValueExpr = new (C) UnresolvedDotExpr (exprToHash, SourceLoc (),
759
759
C.Id_hashValue , DeclNameLoc (),
760
760
/* implicit*/ true );
761
761
762
- // _mixForSynthesizedHashValue (result, <exprToHash>.hashValue)
763
- auto mixinFunc = C.getMixForSynthesizedHashValueDecl ();
764
- auto mixinFuncExpr = new (C) DeclRefExpr (mixinFunc , DeclNameLoc (),
765
- /* implicit*/ true );
762
+ // _combineHashValues (result, <exprToHash>.hashValue)
763
+ auto combineFunc = C.getCombineHashValuesDecl ();
764
+ auto combineFuncExpr = new (C) DeclRefExpr (combineFunc , DeclNameLoc (),
765
+ /* implicit*/ true );
766
766
auto rhsResultExpr = new (C) DeclRefExpr (resultVar, DeclNameLoc (),
767
767
/* implicit*/ true );
768
- auto mixinResultExpr = CallExpr::createImplicit (
769
- C, mixinFuncExpr , { rhsResultExpr, hashValueExpr }, {});
768
+ auto combineResultExpr = CallExpr::createImplicit (
769
+ C, combineFuncExpr , { rhsResultExpr, hashValueExpr }, {});
770
770
771
- // result = _mixForSynthesizedHashValue (result, <exprToHash>.hashValue)
771
+ // result = _combineHashValues (result, <exprToHash>.hashValue)
772
772
auto lhsResultExpr = new (C) DeclRefExpr (resultVar, DeclNameLoc (),
773
773
/* implicit*/ true );
774
774
auto assignExpr = new (C) AssignExpr (lhsResultExpr, SourceLoc (),
775
- mixinResultExpr , /* implicit*/ true );
775
+ combineResultExpr , /* implicit*/ true );
776
776
return assignExpr;
777
777
}
778
778
@@ -853,9 +853,9 @@ deriveBodyHashable_enum_hashValue(AbstractFunctionDecl *hashValueDecl) {
853
853
854
854
// If the enum has no associated values, we use the ordinal alone as the
855
855
// hash value, because that is sufficient for a good distribution. If any
856
- // case do have associated values, then the ordinal is used as the first
857
- // term mixed into _mixForSynthesizedHashValue , and the final result after
858
- // mixing in the payload is passed to _mixInt to improve the distribution.
856
+ // case does have associated values, then the ordinal is used as the first
857
+ // term combined into _combineHashValues , and the final result after
858
+ // combining the payload is passed to _mixInt to improve the distribution.
859
859
860
860
// result = <ordinal>
861
861
{
@@ -868,13 +868,14 @@ deriveBodyHashable_enum_hashValue(AbstractFunctionDecl *hashValueDecl) {
868
868
}
869
869
870
870
if (!hasNoAssociatedValues) {
871
- // Generate a sequence of expressions that mix the payload's hash values
872
- // into result.
871
+ // Generate a sequence of expressions that combine the payload's hash
872
+ // values into result.
873
873
for (auto payloadVar : payloadVars) {
874
874
auto payloadVarRef = new (C) DeclRefExpr (payloadVar, DeclNameLoc (),
875
875
/* implicit*/ true );
876
- // result = _mixForSynthesizedHashValue(result, <payloadVar>.hashValue)
877
- auto mixExpr = mixInHashExpr_hashValue (C, resultVar, payloadVarRef);
876
+ // result = _combineHashValues(result, <payloadVar>.hashValue)
877
+ auto mixExpr = combineHashValuesAssignmentExpr (C, resultVar,
878
+ payloadVarRef);
878
879
mixExpressions.emplace_back (ASTNode (mixExpr));
879
880
}
880
881
@@ -953,7 +954,7 @@ deriveBodyHashable_struct_hashValue(AbstractFunctionDecl *hashValueDecl) {
953
954
auto storedProperties =
954
955
structDecl->getStoredProperties (/* skipInaccessible=*/ true );
955
956
956
- // For each stored property, generate a statement that mixes its hash value
957
+ // For each stored property, generate a statement that combines its hash value
957
958
// into the result.
958
959
for (auto propertyDecl : storedProperties) {
959
960
auto propertyRef = new (C) DeclRefExpr (propertyDecl, DeclNameLoc (),
@@ -962,8 +963,9 @@ deriveBodyHashable_struct_hashValue(AbstractFunctionDecl *hashValueDecl) {
962
963
/* implicit*/ true );
963
964
auto selfPropertyExpr = new (C) DotSyntaxCallExpr (propertyRef, SourceLoc (),
964
965
selfRef);
965
- // result = _mixForSynthesizedHashValue(result, <property>.hashValue)
966
- auto mixExpr = mixInHashExpr_hashValue (C, resultVar, selfPropertyExpr);
966
+ // result = _combineHashValues(result, <property>.hashValue)
967
+ auto mixExpr = combineHashValuesAssignmentExpr (C, resultVar,
968
+ selfPropertyExpr);
967
969
statements.emplace_back (ASTNode (mixExpr));
968
970
}
969
971
@@ -1014,11 +1016,11 @@ deriveHashable_hashValue(TypeChecker &tc, Decl *parentDecl,
1014
1016
// result = 0
1015
1017
// case B(let a0):
1016
1018
// result = 1
1017
- // result = _mixForSynthesizedHashValue (result, a0.hashValue)
1019
+ // result = _combineHashValues (result, a0.hashValue)
1018
1020
// case C(let a0, let a1):
1019
1021
// result = 2
1020
- // result = _mixForSynthesizedHashValue (result, a0.hashValue)
1021
- // result = _mixForSynthesizedHashValue (result, a1.hashValue)
1022
+ // result = _combineHashValues (result, a0.hashValue)
1023
+ // result = _combineHashValues (result, a1.hashValue)
1022
1024
// }
1023
1025
// result = _mixInt(result)
1024
1026
// return result
@@ -1030,8 +1032,8 @@ deriveHashable_hashValue(TypeChecker &tc, Decl *parentDecl,
1030
1032
// var y: String
1031
1033
// @derived var hashValue: Int {
1032
1034
// var result: Int = 0
1033
- // result = _mixForSynthesizedHashValue (result, x.hashValue)
1034
- // result = _mixForSynthesizedHashValue (result, y.hashValue)
1035
+ // result = _combineHashValues (result, x.hashValue)
1036
+ // result = _combineHashValues (result, y.hashValue)
1035
1037
// result = _mixInt(result)
1036
1038
// return result
1037
1039
// }
0 commit comments