Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inefficient codegen for field return #23741

Open
arnetheduck opened this issue Jun 19, 2024 · 2 comments
Open

Inefficient codegen for field return #23741

arnetheduck opened this issue Jun 19, 2024 · 2 comments

Comments

@arnetheduck
Copy link
Contributor

Description

type X = object
  v: string

proc fff(input: string): X =
  X(v: input)

proc ggg(input: string): X =
  fff(input)

proc hhh(input: string): string =
  ggg(input).v # inefficient copy

proc hhh2(input: string): string =
  let v = ggg(input)
  v.v

hhh and hhh2 are semantically equivalent and yet in hhh the string is copied - this introduces significant inefficiency for sum type-like constructs.

N_LIB_PRIVATE N_NIMCALL(NimStringV2, _ZN6testit3hhhE6string)(NimStringV2 input_p0) {
	NimStringV2 result;
	tyObject_X__DSqG4yj45rrZSFUFxlmNRw colontmpD_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	nimZeroMem((void*)(&colontmpD_), sizeof(tyObject_X__DSqG4yj45rrZSFUFxlmNRw));
	colontmpD_ = _ZN6testit3gggE6string(input_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	_ZN6system7eqcopy_E3varI6stringE6string((&result), colontmpD_.v);
	_ZN6testit10eqdestroy_E3varIN6testit1XEE((&colontmpD_));
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, _ZN6testit4hhh2E6string)(NimStringV2 input_p0) {
	NimStringV2 result;
	tyObject_X__DSqG4yj45rrZSFUFxlmNRw v;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	nimZeroMem((void*)(&v), sizeof(tyObject_X__DSqG4yj45rrZSFUFxlmNRw));
	v = _ZN6testit3gggE6string(input_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	result = v.v;
	_ZN6system11eqwasMoved_E3varI6stringE((&v.v));
	_ZN6testit10eqdestroy_E3varIN6testit1XEE((&v));
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, _ZN6testit4hhh3E6string)(NimStringV2 input_p0) {
	NimStringV2 result;
	tyObject_X__DSqG4yj45rrZSFUFxlmNRw v;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	nimZeroMem((void*)(&v), sizeof(tyObject_X__DSqG4yj45rrZSFUFxlmNRw));
	v = _ZN6testit3gggE6string(input_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	result = v.v;
	_ZN6system11eqwasMoved_E3varI6stringE((&v.v));
	_ZN6testit10eqdestroy_E3varIN6testit1XEE((&v));
	}BeforeRet_: ;
	return result;

Nim Version

2.0, devel

Current Output

No response

Expected Output

No response

Possible Solution

No response

Additional Information

No response

@ringabout
Copy link
Member

Related to #23395

@arnetheduck
Copy link
Contributor Author

Related to #23395

yeah that one is for refc (which would be the priority to fix as far as we're concerned) - this one is for orc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants