Skip to content

Commit b90cab6

Browse files
committed
[NFC] Made indexing on AsyncContextLayout private.
Previously the methods for getting the index into the layout were public and were being used to directly access the underlying buffer. Here, that abstraction leakage is fixed and field access is forced to go through the appropriate methods.
1 parent 72051ef commit b90cab6

File tree

2 files changed

+31
-38
lines changed

2 files changed

+31
-38
lines changed

lib/IRGen/GenCall.h

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,42 @@ namespace irgen {
109109
NecessaryBindings bindings;
110110
SmallVector<ArgumentInfo, 4> argumentInfos;
111111

112+
unsigned getErrorIndex() { return (unsigned)FixedIndex::Error; }
113+
unsigned getFirstIndirectReturnIndex() {
114+
return getErrorIndex() + getErrorCount();
115+
}
116+
unsigned getLocalContextIndex() {
117+
assert(hasLocalContext());
118+
return getFirstIndirectReturnIndex() + getIndirectReturnCount();
119+
}
120+
unsigned getIndexAfterLocalContext() {
121+
return getFirstIndirectReturnIndex() + getIndirectReturnCount() +
122+
(hasLocalContext() ? 1 : 0);
123+
}
124+
unsigned getBindingsIndex() {
125+
assert(hasBindings());
126+
return getIndexAfterLocalContext();
127+
}
128+
unsigned getFirstArgumentIndex() {
129+
return getIndexAfterLocalContext() + (hasBindings() ? 1 : 0);
130+
}
131+
unsigned getIndexAfterArguments() {
132+
return getFirstArgumentIndex() + getArgumentCount();
133+
}
134+
unsigned getFirstDirectReturnIndex() { return getIndexAfterArguments(); }
135+
112136
public:
113137
bool canHaveError() { return canHaveValidError; }
114-
unsigned getErrorIndex() { return (unsigned)FixedIndex::Error; }
115138
ElementLayout getErrorLayout() { return getElement(getErrorIndex()); }
116139
unsigned getErrorCount() { return (unsigned)FixedCount::Error; }
117140
SILType getErrorType() { return errorType; }
118141

119-
unsigned getFirstIndirectReturnIndex() {
120-
return getErrorIndex() + getErrorCount();
121-
}
122142
ElementLayout getIndirectReturnLayout(unsigned index) {
123143
return getElement(getFirstIndirectReturnIndex() + index);
124144
}
125145
unsigned getIndirectReturnCount() { return indirectReturnInfos.size(); }
126146

127147
bool hasLocalContext() { return (bool)localContextInfo; }
128-
unsigned getLocalContextIndex() {
129-
assert(hasLocalContext());
130-
return getFirstIndirectReturnIndex() + getIndirectReturnCount();
131-
}
132148
ElementLayout getLocalContextLayout() {
133149
assert(hasLocalContext());
134150
return getElement(getLocalContextIndex());
@@ -141,48 +157,30 @@ namespace irgen {
141157
assert(hasLocalContext());
142158
return localContextInfo->type;
143159
}
144-
unsigned getIndexAfterLocalContext() {
145-
return getFirstIndirectReturnIndex() + getIndirectReturnCount() +
146-
(hasLocalContext() ? 1 : 0);
147-
}
148160

149161
bool hasBindings() const { return !bindings.empty(); }
150-
unsigned getBindingsIndex() {
151-
assert(hasBindings());
152-
return getIndexAfterLocalContext();
153-
}
154162
ElementLayout getBindingsLayout() {
155163
assert(hasBindings());
156164
return getElement(getBindingsIndex());
157165
}
158-
ParameterConvention getBindingsConvention() {
159-
return ParameterConvention::Direct_Unowned;
160-
}
161166
const NecessaryBindings &getBindings() const { return bindings; }
162167

163-
unsigned getFirstArgumentIndex() {
164-
return getIndexAfterLocalContext() + (hasBindings() ? 1 : 0);
165-
}
166168
ElementLayout getArgumentLayout(unsigned index) {
167169
return getElement(getFirstArgumentIndex() + index);
168170
}
169-
ParameterConvention getArgumentConvention(unsigned index) {
170-
return argumentInfos[index].convention;
171-
}
172171
SILType getArgumentType(unsigned index) {
173172
return argumentInfos[index].type;
174173
}
174+
// Returns the type of a parameter of the substituted function using the
175+
// indexing of the function parameters, *not* the indexing of
176+
// AsyncContextLayout.
175177
SILType getParameterType(unsigned index) {
176178
SILFunctionConventions origConv(substitutedType, IGF.getSILModule());
177179
return origConv.getSILArgumentType(
178180
index, IGF.IGM.getMaximalTypeExpansionContext());
179181
}
180182
unsigned getArgumentCount() { return argumentInfos.size(); }
181-
unsigned getIndexAfterArguments() {
182-
return getFirstArgumentIndex() + getArgumentCount();
183-
}
184183

185-
unsigned getFirstDirectReturnIndex() { return getIndexAfterArguments(); }
186184
unsigned getDirectReturnCount() { return directReturnInfos.size(); }
187185
ElementLayout getDirectReturnLayout(unsigned index) {
188186
return getElement(getFirstDirectReturnIndex() + index);

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,9 +1261,7 @@ class AsyncNativeCCEntryPointArgumentEmission final
12611261
}
12621262
llvm::Value *getIndirectResult(unsigned index) override {
12631263
Address dataAddr = layout.emitCastTo(IGF, context);
1264-
unsigned baseIndirectReturnIndex = layout.getFirstIndirectReturnIndex();
1265-
unsigned elementIndex = baseIndirectReturnIndex + index;
1266-
auto &fieldLayout = layout.getElement(elementIndex);
1264+
auto fieldLayout = layout.getIndirectReturnLayout(index);
12671265
Address fieldAddr =
12681266
fieldLayout.project(IGF, dataAddr, /*offsets*/ llvm::None);
12691267
return IGF.Builder.CreateLoad(fieldAddr);
@@ -3101,16 +3099,13 @@ static void emitReturnInst(IRGenSILFunction &IGF,
31013099
auto layout = getAsyncContextLayout(IGF);
31023100

31033101
Address dataAddr = layout.emitCastTo(IGF, context);
3104-
unsigned index = layout.getFirstDirectReturnIndex();
3105-
for (auto r :
3106-
IGF.CurSILFn->getLoweredFunctionType()->getDirectFormalResults()) {
3107-
(void)r;
3108-
auto &fieldLayout = layout.getElement(index);
3102+
for (unsigned index = 0, count = layout.getDirectReturnCount();
3103+
index < count; ++index) {
3104+
auto fieldLayout = layout.getDirectReturnLayout(index);
31093105
Address fieldAddr =
31103106
fieldLayout.project(IGF, dataAddr, /*offsets*/ llvm::None);
31113107
cast<LoadableTypeInfo>(fieldLayout.getType())
31123108
.initialize(IGF, result, fieldAddr, /*isOutlined*/ false);
3113-
++index;
31143109
}
31153110
IGF.Builder.CreateRetVoid();
31163111
} else {

0 commit comments

Comments
 (0)