Skip to content

Commit 2f471db

Browse files
committed
migrate keyword names to use a BoxedTuple of BoxedStrings
1 parent 176d765 commit 2f471db

File tree

18 files changed

+95
-131
lines changed

18 files changed

+95
-131
lines changed

src/capi/typeobject.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,8 +3454,7 @@ extern "C" void PyType_Modified(PyTypeObject* type) noexcept {
34543454

34553455
template <ExceptionStyle S>
34563456
static Box* tppProxyToTpCall(Box* self, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2,
3457-
Box* arg3, Box** args,
3458-
const std::vector<BoxedString*>* keyword_names) noexcept(S == CAPI) {
3457+
Box* arg3, Box** args, BoxedTuple* keyword_names) noexcept(S == CAPI) {
34593458
ParamReceiveSpec paramspec(0, 0, true, true);
34603459
if (!argspec.has_kwargs && argspec.num_keywords == 0) {
34613460
paramspec.takes_kwargs = false;

src/capi/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class BoxedCApiFunction : public Box {
5454
static Box* __call__(BoxedCApiFunction* self, BoxedTuple* varargs, BoxedDict* kwargs);
5555
template <ExceptionStyle S>
5656
static Box* tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2, Box* arg3,
57-
Box** args, const std::vector<BoxedString*>* keyword_names) noexcept(S == CAPI);
57+
Box** args, BoxedTuple* keyword_names) noexcept(S == CAPI);
5858

5959
static Box* getname(Box* b, void*) noexcept {
6060
RELEASE_ASSERT(b->cls == capifunc_cls, "");

src/codegen/ast_interpreter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,9 +1457,9 @@ Value ASTInterpreter::visit_call(BST_Call* node) {
14571457
args_vars.push_back(v);
14581458
}
14591459

1460-
const std::vector<BoxedString*>* keyword_names = NULL;
1460+
BoxedTuple* keyword_names = NULL;
14611461
if (node->num_keywords)
1462-
keyword_names = getCodeConstants().getKeywordNames(node->index_keyword_names);
1462+
keyword_names = (BoxedTuple*)getCodeConstants().getConstant(node->index_keyword_names);
14631463

14641464
if (node->vreg_starargs != VREG_UNDEFINED) {
14651465
Value v = getVReg(node->vreg_starargs);

src/codegen/baseline_jit.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ RewriterVar* JitFragmentWriter::emitBinop(BST_stmt* node, RewriterVar* lhs, Rewr
245245
}
246246

247247
RewriterVar* JitFragmentWriter::emitCallattr(BST_stmt* node, RewriterVar* obj, BoxedString* attr, CallattrFlags flags,
248-
const llvm::ArrayRef<RewriterVar*> args,
249-
const std::vector<BoxedString*>* keyword_names) {
248+
const llvm::ArrayRef<RewriterVar*> args, BoxedTuple* keyword_names) {
250249
#if ENABLE_BASELINEJIT_ICS
251250
RewriterVar* attr_var = imm(attr);
252251
RewriterVar* flags_var = imm(flags.asInt());
@@ -519,8 +518,7 @@ RewriterVar* JitFragmentWriter::emitRepr(RewriterVar* v) {
519518
}
520519

521520
RewriterVar* JitFragmentWriter::emitRuntimeCall(BST_stmt* node, RewriterVar* obj, ArgPassSpec argspec,
522-
const llvm::ArrayRef<RewriterVar*> args,
523-
const std::vector<BoxedString*>* keyword_names) {
521+
const llvm::ArrayRef<RewriterVar*> args, BoxedTuple* keyword_names) {
524522
#if ENABLE_BASELINEJIT_ICS
525523
RewriterVar* argspec_var = imm(argspec.asInt());
526524
RewriterVar::SmallVector call_args;
@@ -1002,7 +1000,7 @@ void JitFragmentWriter::assertNameDefinedHelper(const char* id) {
10021000
}
10031001

10041002
Box* JitFragmentWriter::callattrHelper(Box* obj, BoxedString* attr, CallattrFlags flags, Box** args,
1005-
const std::vector<BoxedString*>* keyword_names) {
1003+
BoxedTuple* keyword_names) {
10061004
auto arg_tuple = getTupleFromArgsArray(&args[0], flags.argspec.totalPassed());
10071005
Box* r = callattr(obj, attr, flags, std::get<0>(arg_tuple), std::get<1>(arg_tuple), std::get<2>(arg_tuple),
10081006
std::get<3>(arg_tuple), keyword_names);
@@ -1060,8 +1058,7 @@ BORROWED(Box*) JitFragmentWriter::notHelper(Box* b) {
10601058
return b->nonzeroIC() ? Py_False : Py_True;
10611059
}
10621060

1063-
Box* JitFragmentWriter::runtimeCallHelper(Box* obj, ArgPassSpec argspec, Box** args,
1064-
const std::vector<BoxedString*>* keyword_names) {
1061+
Box* JitFragmentWriter::runtimeCallHelper(Box* obj, ArgPassSpec argspec, Box** args, BoxedTuple* keyword_names) {
10651062
auto arg_tuple = getTupleFromArgsArray(&args[0], argspec.totalPassed());
10661063
Box* r = runtimeCall(obj, argspec, std::get<0>(arg_tuple), std::get<1>(arg_tuple), std::get<2>(arg_tuple),
10671064
std::get<3>(arg_tuple), keyword_names);

src/codegen/baseline_jit.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class JitFragmentWriter : ICInfoManager, public Rewriter {
270270
RewriterVar* emitApplySlice(RewriterVar* target, RewriterVar* lower, RewriterVar* upper);
271271
RewriterVar* emitBinop(BST_stmt* node, RewriterVar* lhs, RewriterVar* rhs, int op_type);
272272
RewriterVar* emitCallattr(BST_stmt* node, RewriterVar* obj, BoxedString* attr, CallattrFlags flags,
273-
const llvm::ArrayRef<RewriterVar*> args, const std::vector<BoxedString*>* keyword_names);
273+
const llvm::ArrayRef<RewriterVar*> args, BoxedTuple* keyword_names);
274274
RewriterVar* emitCompare(BST_stmt* node, RewriterVar* lhs, RewriterVar* rhs, int op_type);
275275
RewriterVar* emitCreateDict();
276276
void emitDictSet(RewriterVar* dict, RewriterVar* k, RewriterVar* v);
@@ -301,8 +301,7 @@ class JitFragmentWriter : ICInfoManager, public Rewriter {
301301
RewriterVar* emitNotNonzero(RewriterVar* v);
302302
RewriterVar* emitRepr(RewriterVar* v);
303303
RewriterVar* emitRuntimeCall(BST_stmt* node, RewriterVar* obj, ArgPassSpec argspec,
304-
const llvm::ArrayRef<RewriterVar*> args,
305-
const std::vector<BoxedString*>* keyword_names);
304+
const llvm::ArrayRef<RewriterVar*> args, BoxedTuple* keyword_names);
306305
RewriterVar* emitUnaryop(RewriterVar* v, int op_type);
307306
std::vector<RewriterVar*> emitUnpackIntoArray(RewriterVar* v, uint64_t num);
308307
RewriterVar* emitYield(RewriterVar* v);
@@ -359,8 +358,7 @@ class JitFragmentWriter : ICInfoManager, public Rewriter {
359358
llvm::ArrayRef<RewriterVar*> additional_uses = {});
360359

361360
static void assertNameDefinedHelper(const char* id);
362-
static Box* callattrHelper(Box* obj, BoxedString* attr, CallattrFlags flags, Box** args,
363-
const std::vector<BoxedString*>* keyword_names);
361+
static Box* callattrHelper(Box* obj, BoxedString* attr, CallattrFlags flags, Box** args, BoxedTuple* keyword_names);
364362
static Box* createDictHelper(uint64_t num, Box** keys, Box** values);
365363
static Box* createListHelper(uint64_t num, Box** data);
366364
static Box* createSetHelper(uint64_t num, Box** data);
@@ -369,8 +367,7 @@ class JitFragmentWriter : ICInfoManager, public Rewriter {
369367
static BORROWED(Box*) hasnextHelper(Box* b);
370368
static BORROWED(Box*) nonzeroHelper(Box* b);
371369
static BORROWED(Box*) notHelper(Box* b);
372-
static Box* runtimeCallHelper(Box* obj, ArgPassSpec argspec, Box** args,
373-
const std::vector<BoxedString*>* keyword_names);
370+
static Box* runtimeCallHelper(Box* obj, ArgPassSpec argspec, Box** args, BoxedTuple* keyword_names);
374371

375372
void _emitGetLocal(RewriterVar* val_var, const char* name);
376373
void _emitJump(CFGBlock* b, RewriterVar* block_next, ExitInfo& exit_info);

src/codegen/compvars.cpp

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class InstanceMethodType : public ValuedCompilerType<RawInstanceMethod*> {
138138

139139
CompilerVariable* call(IREmitter& emitter, const OpInfo& info, ValuedCompilerVariable<RawInstanceMethod*>* var,
140140
ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
141-
const std::vector<BoxedString*>* keyword_names) override {
141+
BoxedTuple* keyword_names) override {
142142
std::vector<CompilerVariable*> new_args;
143143
new_args.push_back(var->getValue()->obj);
144144
new_args.insert(new_args.end(), args.begin(), args.end());
@@ -225,11 +225,10 @@ class UnknownType : public ConcreteCompilerType {
225225
CompilerVariable* getattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr,
226226
bool cls_only) override;
227227
CompilerVariable* call(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, ArgPassSpec argspec,
228-
const std::vector<CompilerVariable*>& args,
229-
const std::vector<BoxedString*>* keyword_names) override;
228+
const std::vector<CompilerVariable*>& args, BoxedTuple* keyword_names) override;
230229
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr,
231230
CallattrFlags flags, const std::vector<CompilerVariable*>& args,
232-
const std::vector<BoxedString*>* keyword_names) override;
231+
BoxedTuple* keyword_names) override;
233232
ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var) override;
234233
ConcreteCompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
235234
AST_TYPE::AST_TYPE op_type) override;
@@ -593,10 +592,11 @@ CompilerVariable* UnknownType::getattr(IREmitter& emitter, const OpInfo& info, C
593592
return new ConcreteCompilerVariable(UNKNOWN, rtn_val);
594593
}
595594

596-
static ConcreteCompilerVariable*
597-
_call(IREmitter& emitter, const OpInfo& info, llvm::Value* func, ExceptionStyle target_exception_style, void* func_addr,
598-
const std::vector<llvm::Value*>& other_args, ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
599-
const std::vector<BoxedString*>* keyword_names, ConcreteCompilerType* rtn_type, bool nullable_return = false) {
595+
static ConcreteCompilerVariable* _call(IREmitter& emitter, const OpInfo& info, llvm::Value* func,
596+
ExceptionStyle target_exception_style, void* func_addr,
597+
const std::vector<llvm::Value*>& other_args, ArgPassSpec argspec,
598+
const std::vector<CompilerVariable*>& args, BoxedTuple* keyword_names,
599+
ConcreteCompilerType* rtn_type, bool nullable_return = false) {
600600
bool pass_keyword_names = (keyword_names != nullptr);
601601
assert(pass_keyword_names == (argspec.num_keywords > 0));
602602

@@ -718,7 +718,7 @@ _call(IREmitter& emitter, const OpInfo& info, llvm::Value* func, ExceptionStyle
718718

719719
CompilerVariable* UnknownType::call(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
720720
ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
721-
const std::vector<BoxedString*>* keyword_names) {
721+
BoxedTuple* keyword_names) {
722722
bool pass_keywords = (argspec.num_keywords != 0);
723723
int npassed_args = argspec.totalPassed();
724724

@@ -750,8 +750,7 @@ CompilerVariable* UnknownType::call(IREmitter& emitter, const OpInfo& info, Conc
750750

751751
CompilerVariable* UnknownType::callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
752752
BoxedString* attr, CallattrFlags flags,
753-
const std::vector<CompilerVariable*>& args,
754-
const std::vector<BoxedString*>* keyword_names) {
753+
const std::vector<CompilerVariable*>& args, BoxedTuple* keyword_names) {
755754
bool pass_keywords = (flags.argspec.num_keywords != 0);
756755
int npassed_args = flags.argspec.totalPassed();
757756

@@ -1163,8 +1162,7 @@ class IntType : public UnboxedType<llvm::Value*, IntType> {
11631162
}
11641163

11651164
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, BoxedString* attr, CallattrFlags flags,
1166-
const std::vector<CompilerVariable*>& args,
1167-
const std::vector<BoxedString*>* keyword_names) override {
1165+
const std::vector<CompilerVariable*>& args, BoxedTuple* keyword_names) override {
11681166
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_INT);
11691167
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
11701168
return rtn;
@@ -1451,8 +1449,7 @@ class FloatType : public UnboxedType<llvm::Value*, FloatType> {
14511449
}
14521450

14531451
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, BoxedString* attr, CallattrFlags flags,
1454-
const std::vector<CompilerVariable*>& args,
1455-
const std::vector<BoxedString*>* keyword_names) override {
1452+
const std::vector<CompilerVariable*>& args, BoxedTuple* keyword_names) override {
14561453
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_FLOAT);
14571454
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
14581455
return rtn;
@@ -1839,18 +1836,16 @@ class NormalObjectType : public ConcreteCompilerType {
18391836
}
18401837

18411838
CompilerVariable* call(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, ArgPassSpec argspec,
1842-
const std::vector<CompilerVariable*>& args,
1843-
const std::vector<BoxedString*>* keyword_names) override {
1839+
const std::vector<CompilerVariable*>& args, BoxedTuple* keyword_names) override {
18441840
ConcreteCompilerVariable* converted = var->makeConverted(emitter, UNKNOWN);
18451841
CompilerVariable* rtn = converted->call(emitter, info, argspec, args, keyword_names);
18461842
return rtn;
18471843
}
18481844

18491845
CompilerVariable* tryCallattrConstant(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
18501846
BoxedString* attr, bool clsonly, ArgPassSpec argspec,
1851-
const std::vector<CompilerVariable*>& args,
1852-
const std::vector<BoxedString*>* keyword_names, bool* no_attribute = NULL,
1853-
ExceptionStyle exception_style = CXX) {
1847+
const std::vector<CompilerVariable*>& args, BoxedTuple* keyword_names,
1848+
bool* no_attribute = NULL, ExceptionStyle exception_style = CXX) {
18541849
if (!canStaticallyResolveGetattrs())
18551850
return NULL;
18561851

@@ -2002,7 +1997,7 @@ class NormalObjectType : public ConcreteCompilerType {
20021997

20031998
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr,
20041999
CallattrFlags flags, const std::vector<CompilerVariable*>& args,
2005-
const std::vector<BoxedString*>* keyword_names) override {
2000+
BoxedTuple* keyword_names) override {
20062001
ExceptionStyle exception_style = info.preferredExceptionStyle();
20072002

20082003
bool no_attribute = false;
@@ -2314,8 +2309,7 @@ class StrConstantType : public ValuedCompilerType<BoxedString*> {
23142309
}
23152310

23162311
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, BoxedString* attr, CallattrFlags flags,
2317-
const std::vector<CompilerVariable*>& args,
2318-
const std::vector<BoxedString*>* keyword_names) override {
2312+
const std::vector<CompilerVariable*>& args, BoxedTuple* keyword_names) override {
23192313
ConcreteCompilerVariable* converted = var->makeConverted(emitter, STR);
23202314
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
23212315
return rtn;
@@ -2434,7 +2428,7 @@ class BoolType : public ConcreteCompilerType {
24342428

24352429
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr,
24362430
CallattrFlags flags, const std::vector<CompilerVariable*>& args,
2437-
const std::vector<BoxedString*>* keyword_names) override {
2431+
BoxedTuple* keyword_names) override {
24382432
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_BOOL);
24392433
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
24402434
return rtn;
@@ -2670,8 +2664,7 @@ class TupleType : public UnboxedType<const std::vector<CompilerVariable*>, Tuple
26702664
}
26712665

26722666
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, BoxedString* attr, CallattrFlags flags,
2673-
const std::vector<CompilerVariable*>& args,
2674-
const std::vector<BoxedString*>* keyword_names) override {
2667+
const std::vector<CompilerVariable*>& args, BoxedTuple* keyword_names) override {
26752668
return makeConverted(emitter, var, getConcreteType())
26762669
->callattr(emitter, info, attr, flags, args, keyword_names);
26772670
}
@@ -2812,8 +2805,7 @@ class UndefType : public ConcreteCompilerType {
28122805
}
28132806

28142807
CompilerVariable* call(IREmitter& emitter, const OpInfo& info, VAR* var, ArgPassSpec argspec,
2815-
const std::vector<CompilerVariable*>& args,
2816-
const std::vector<BoxedString*>* keyword_names) override {
2808+
const std::vector<CompilerVariable*>& args, BoxedTuple* keyword_names) override {
28172809
return undefVariable();
28182810
}
28192811
CompilerVariable* dup(VAR* v, DupCache& cache) override {
@@ -2834,8 +2826,7 @@ class UndefType : public ConcreteCompilerType {
28342826
}
28352827

28362828
CompilerVariable* callattr(IREmitter& emitter, const OpInfo& info, VAR* var, BoxedString* attr, CallattrFlags flags,
2837-
const std::vector<CompilerVariable*>& args,
2838-
const std::vector<BoxedString*>* keyword_names) override {
2829+
const std::vector<CompilerVariable*>& args, BoxedTuple* keyword_names) override {
28392830
return undefVariable();
28402831
}
28412832

0 commit comments

Comments
 (0)