rokucommunity / rokucommunity/brighterscript
Runtime overloaded functions
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 208
- Forks
- 68
- Avg merge
- 8h 39m
- Merged PRs (30d)
- 39
Description
Unlike https://github.com/rokucommunity/brighterscript/issues/444 which is only at typetime/compiletime, this proposal is to implement actual transpile support.
Given this source code:
function getPrice(price as integer)
return price
end function
function getPrice(price as string)
return toNumber(price)
end function
function main()
price = getPrice(100)
price = getPrice("200")
someNum = 100 as dynamic
price = getPrice(someNum)
end function
It would transpile to:
function getPrice_1(price as integer)
return price
end function
function getPrice_2(price as string)
return toNumber(price)
end function
function getPrice(price as dynamic)
if type(price) = "number"
return getPrice_1(price)
else
return getPrice_2(price)
end if
end function
function main()
price = getPrice_1(100)
price = getPrice_2("200")
someNum = 100 as dynamic
price = getPrice_safe(someNum)
end function
Limitations:
- We probably can't support complex types here (like interfaces) without significant runtime effort to determine the type. So should be limited to only simple things (like primitives, or perhaps specific node types since it's a single check)
- anytime we don't know the type, it would fall into the safe generic one, which will be more expensive than the type-specific overload. However, this is up to the development team to enforce string typing to get the performance benefits of this approach.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the related issue #444 and tracing the compiler's transpilation entry points; this issue names no files or tests. Done means supporting the proposed runtime overload transformation, including type-specific dispatch and a safe fallback for unknown types, within the stated type limitations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100