Skip to content

Add a duck-typing example. - #4899

Open
hzeller wants to merge 1 commit into
google:mainfrom
hzeller:feature-20260903-duck
Open

hzeller wants to merge 1 commit into
google:mainfrom
hzeller:feature-20260903-duck

Conversation

@hzeller

@hzeller hzeller commented Sep 3, 2026

Copy link
Copy Markdown
Member

Even without traits, operations that look the same can be applied to different types.

@hzeller

hzeller commented Sep 3, 2026 •

Copy link
Copy Markdown
Member Author

There is the caveat, that this does not seem to work with the jit yet, this is why that '--compare=jit` is commented out.

It unhelpfully crashes with:

F0903 08:11:47.593204 2704354 function_converter.cc:210] Check failed: requires_opt.has_value() 
*** Check failure stack trace: ***
    @     0x5a9df4a4de74  absl::lts_20260526::log_internal::LogMessage::SendToLog()
    @     0x5a9df4a4de22  absl::lts_20260526::log_internal::LogMessage::Flush()
    @     0x5a9df13b0f3f  xls::dslx::GetRequiresImplicitToken()
    @     0x5a9df13e0b18  xls::dslx::FunctionConverter::HandleFunction()
    @     0x5a9df13996eb  xls::dslx::(anonymous namespace)::ConvertCallGraph()
    @     0x5a9df139741e  xls::dslx::ConvertModuleIntoPackage()
    @     0x5a9df139b070  xls::dslx::ConvertModuleToPackage()
    @     0x5a9df137f6a4  xls::dslx::AbstractTestRunner::ParseAndTest()
    @     0x5a9df13524d0  main
    @     0x7c700fa2b285  __libc_start_call_main
    @     0x7c700fa2b338  __libc_start_main@GLIBC_2.2.5
    @     0x5a9df135036a  _start

Maybe I am also holding it wrong, but it should never crash, but have a useful error message.

In any case, if the code looks good (and there is a desire for a duck type example), then I guess merging and then having a separate bug (Update: that bug is #4901) pointing to the jit situation that then can be resolved in a second step would be good.

@hzeller
hzeller force-pushed the feature-20260903-duck branch 2 times, most recently from fc2b8f8 to 2d1162c Compare September 3, 2026 08:51
@hzeller

hzeller commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

Ok, I found why it crashed (a function declared in impl was never called and thus dead code, but it resulted in a crash of F0903 08:50:49.563064 2705024 function_converter.cc:210] Check failed: requires_opt.has_value()

I'll file a separate bug for that (once this example is in, I can easily point to this example and go from there. So will file after this example is submitted).

For now, I made the example work by actually calling each of the functions in the impl (from() and default() was not called for all tests).

@hzeller
hzeller requested a review from richmckeever September 3, 2026 08:54
@hzeller

hzeller commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

Isolated the issue I was seeing and filed #4901

@hzeller
hzeller force-pushed the feature-20260903-duck branch from 2d1162c to e6b0029 Compare September 4, 2026 08:04
Even without traits, operations that look the same can be applied
to different types.
@hzeller
hzeller force-pushed the feature-20260903-duck branch from e6b0029 to 2e6b02b Compare September 22, 2026 09:39
@hzeller

hzeller commented Sep 22, 2026

Copy link
Copy Markdown
Member Author

#4901 is fixed, so the observation in #4899 (comment) above does not happen anymore.

Maybe this PR went under the radar ? It might be useful, but I don't know if something like this is to be covered by traits and is in the pipeline (didn't find any reference to traits in docs_src/), so until then duck-typing might be one way to do things.

Probably something to review for @richmckeever or @erinzmoore ?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant