v icon indicating copy to clipboard operation
v copied to clipboard

Error `-prod` compiling UI example

Open paul-reilly opened this issue 2 years ago • 8 comments

Describe the bug

Compiling the file (provided further down) works, but when using the -prod flag I get this error:

> C compiler cmd: 'cc' '@/tmp/v_1000/first.5516292057153074927.tmp.c.rsp'
750.556  ms C  cc
==================
      |                                                                                            I_ui__Widget_as_I_ui__WidgetThemeStyle
/tmp/v_1000/first.5516292057153074927.tmp.c:60954:92: error: incompatible type for argument 1 of ‘I_ui__WidgetThemeStyle_as_I_ui__WidgetThemeStyle’
60954 |                 ui__WidgetThemeStyle w = I_ui__WidgetThemeStyle_as_I_ui__WidgetThemeStyle((I_ui__Layout_as_I_ui__WidgetThemeStyle(*l)));
      |                                                                                           ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                            |
      |                                                                                            int
/tmp/v_1000/first.5516292057153074927.tmp.c:16860:106: note: expected ‘ui__WidgetThemeStyle’ but argument is of type ‘int’
16860 | static inline ui__WidgetThemeStyle I_ui__WidgetThemeStyle_as_I_ui__WidgetThemeStyle(ui__WidgetThemeStyle x) {
      |                                                                                     ~~~~~~~~~~~~~~~~~~~~~^
/tmp/v_1000/first.5516292057153074927.tmp.c: In function ‘ui__Menu_propagate_connection’:
/tmp/v_1000/first.5516292057153074927.tmp.c:65494:55: warning: assignment to ‘ui__MenuItem *’ from incompatible pointer type ‘ui__MenuItem **’ [-Wincompatible-pointer-types]
65494 |                         (*item)->submenu->parent_item = item;
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

Expected Behavior

Native compiler to produce a zingy executable.

Current Behavior


Reproduction Steps

The full file, which compiles and runs normally without the -prod flag is:

module main

import ui
import gx

struct State {
mut:
	tb1  string
	tb2m string
	tb3m string
}

fn main() {
	mut app := &State{
		tb1: 'hggyjgyguguglul'
		tb2m: 'toto bbub jhuui jkhuhui hubhuib\ntiti tutu toto\ntata tata'.repeat(1000)
		tb3m: 'toto bbub jhuui jkhuhui hubhuib\ntiti tutu toto\ntata tata'
	}
	lines := app.tb2m.split('\n')
	mut s := ''
	for l in lines {
		s += '${l}\n'
	}
	app.tb2m = s
	c := ui.column(
		widths: ui.stretch
		heights: [ui.compact, ui.compact, ui.stretch, ui.stretch]
		margin_: 5
		spacing: 10
		children: [
			ui.textbox(
				id: 'tb1'
				text: &app.tb1
				fitted_height: true
			),
			ui.row(
				spacing: 5
				children: [
					ui.label(text: 'Word wrap'),
					ui.switcher(open: false, id: 'sw2', on_click: on_switch_click),
					ui.switcher(open: false, id: 'sw3', on_click: on_switch_click),
				]
			),
			ui.textbox(
				mode: .multiline
				id: 'tb2m'
				text: &app.tb2m
				height: 200
				text_size: 24
				bg_color: gx.hex(0xfcf4e4ff) // gx.rgb(252, 244, 228)
			),
			ui.textbox(
				mode: .read_only | .multiline
				id: 'tb3m'
				text: &app.tb2m
				height: 200
				text_size: 24
				on_scroll_change: on_scroll_change
			),
		]
	)
	w := ui.window(
		width: 500
		height: 300
		mode: .resizable
		layout: c
	)
	ui.run(w)
}

fn on_switch_click(switcher &ui.Switch) {
	tbs := if switcher.id == 'sw2' { 'tb2m' } else { 'tb3m' }
	mut tb := switcher.ui.window.get_or_panic[ui.TextBox](tbs)
	tb.tv.switch_wordwrap()
}

fn on_scroll_change(sw ui.ScrollableWidget) {
	// println('sw cb example: $sw.id has scrollview? $sw.has_scrollview with x: $sw.x and y: $sw.y')
}

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.3.3 f41ca48

Environment details (OS name and version, etc.)

Linux 6.1.23-1-MANJARO #1 SMP PREEMPT_DYNAMIC x86_64 GNU/Linux

paul-reilly avatar Apr 12 '23 22:04 paul-reilly

I've tried v -prod -cc gcc-11 run app.v as well as v -prod -cc clang-12 run app.v on Ubuntu 20.04, and both do work.

What compiler version are you using? Please paste the results of cc --version too.

spytheman avatar Apr 14 '23 11:04 spytheman

Thanks for checking, I'm on gcc 12.2.1 and cc is gcc too:

> cc --version
cc (GCC) 12.2.1 20230201
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

paul-reilly avatar Apr 14 '23 14:04 paul-reilly

Try compiling with '-no-parallel' as well.

spytheman avatar Apr 18 '23 09:04 spytheman

It's working now with or without -no-parallel. I had ran v up as well, now on v0.3.3 6cc4208.

paul-reilly avatar Apr 18 '23 10:04 paul-reilly

I get the same error periodically. Happens about 2% of the time.

So it's a hard to reproduce bug, but it's there.

medvednikov avatar Apr 18 '23 10:04 medvednikov

@yuyi98 do you know what could be causing

      |                                                                                            I_ui__Widget_as_I_ui__WidgetThemeStyle
/tmp/v_1000/first.5516292057153074927.tmp.c:60954:92: error: incompatible type for argument 1 of ‘I_ui__WidgetThemeStyle_as_I_ui__WidgetThemeStyle’
60954 |                 ui__WidgetThemeStyle w = I_ui__WidgetThemeStyle_as_I_ui__WidgetThemeStyle((I_ui__Layout_as_I_ui__WidgetThemeStyle(*l)));

medvednikov avatar Apr 18 '23 10:04 medvednikov

Ok, I'll try.

yuyi98 avatar Apr 18 '23 12:04 yuyi98

It's ok on windows.

yuyi98 avatar Apr 18 '23 13:04 yuyi98