[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-12 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16683755#comment-16683755
 ] 

ASF GitHub Bot commented on THRIFT-4662:


jeking3 closed pull request #1624: THRIFT-4662: Rust const string calls 
function at compile time
URL: https://github.com/apache/thrift/pull/1624
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/compiler/cpp/src/thrift/generate/t_rs_generator.cc 
b/compiler/cpp/src/thrift/generate/t_rs_generator.cc
index dc11fd3ee2..eccdd275e0 100644
--- a/compiler/cpp/src/thrift/generate/t_rs_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_rs_generator.cc
@@ -127,7 +127,7 @@ class t_rs_generator : public t_generator {
   void render_const_value_holder(const string& name, t_type* ttype, 
t_const_value* tvalue);
 
   // Write the actual const value - the right side of a const definition.
-  void render_const_value(t_type* ttype, t_const_value* tvalue);
+  void render_const_value(t_type* ttype, t_const_value* tvalue, bool is_owned 
= true);
 
   // Write a const struct (returned from `const_value` method).
   void render_const_struct(t_type* ttype, t_const_value* tvalue);
@@ -411,6 +411,9 @@ class t_rs_generator : public t_generator {
   // Return a string representing the rust type given a `t_type`.
   string to_rust_type(t_type* ttype, bool ordered_float = true);
 
+  // Return a string representing the `const` rust type given a `t_type`
+  string to_rust_const_type(t_type* ttype, bool ordered_float = true);
+
   // Return a string representing the rift `protocol::TType` given a `t_type`.
   string to_rust_field_type_enum(t_type* ttype);
 
@@ -645,8 +648,8 @@ void t_rs_generator::render_const_value(const string& name, 
t_type* ttype, t_con
 throw "cannot generate simple rust constant for " + ttype->get_name();
   }
 
-  f_gen_ << "pub const " << rust_upper_case(name) << ": " << 
to_rust_type(ttype) << " = ";
-  render_const_value(ttype, tvalue);
+  f_gen_ << "pub const " << rust_upper_case(name) << ": " << 
to_rust_const_type(ttype) << " = ";
+  render_const_value(ttype, tvalue, false);
   f_gen_ << ";" << endl;
   f_gen_ << endl;
 }
@@ -673,15 +676,22 @@ void t_rs_generator::render_const_value_holder(const 
string& name, t_type* ttype
   f_gen_ << endl;
 }
 
-void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue) {
+void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue, 
bool is_owned) {
   if (ttype->is_base_type()) {
 t_base_type* tbase_type = (t_base_type*)ttype;
 switch (tbase_type->get_base()) {
 case t_base_type::TYPE_STRING:
   if (tbase_type->is_binary()) {
-f_gen_ << "\"" << tvalue->get_string() << "\""<<  
".to_owned().into_bytes()";
+if (is_owned) {
+  f_gen_ << "\"" << tvalue->get_string() << "\""<<  
".to_owned().into_bytes()";
+} else {
+  f_gen_ << "b\"" << tvalue->get_string() << "\"";
+}
   } else {
-f_gen_ << "\"" << tvalue->get_string() << "\""<<  ".to_owned()";
+f_gen_ << "\"" << tvalue->get_string() << "\"";
+if (is_owned) {
+  f_gen_ << ".to_owned()";
+}
   }
   break;
 case t_base_type::TYPE_BOOL:
@@ -3039,6 +3049,21 @@ string t_rs_generator::to_rust_type(t_type* ttype, bool 
ordered_float) {
   throw "cannot find rust type for " + ttype->get_name();
 }
 
+string t_rs_generator::to_rust_const_type(t_type* ttype, bool ordered_float) {
+  if (ttype->is_base_type()) {
+t_base_type* tbase_type = ((t_base_type*)ttype);
+if (tbase_type->get_base() == t_base_type::TYPE_STRING) {
+  if (tbase_type->is_binary()) {
+return "&[u8]";
+  } else {
+return "";
+  }
+}
+  }
+
+  return to_rust_type(ttype, ordered_float);
+}
+
 string t_rs_generator::to_rust_field_type_enum(t_type* ttype) {
   ttype = get_true_type(ttype);
   if (ttype->is_base_type()) {
diff --git a/lib/rs/test/thrifts/Base_One.thrift 
b/lib/rs/test/thrifts/Base_One.thrift
index 3da083d451..c5fa6c20df 100644
--- a/lib/rs/test/thrifts/Base_One.thrift
+++ b/lib/rs/test/thrifts/Base_One.thrift
@@ -37,6 +37,9 @@ const list CommonTemperatures = [300.0, 450.0]
 
 const double MealsPerDay = 2.5;
 
+const string DefaultRecipeName = "Soup-rise of the Day"
+const binary DefaultRecipeBinary = "Soup-rise of the 01010101"
+
 struct Noodle {
   1: string flourType
   2: Temperature cookTemp


 


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact 

[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-12 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16683665#comment-16683665
 ] 

ASF GitHub Bot commented on THRIFT-4662:


allengeorge commented on issue #1624: THRIFT-4662: Rust const string calls 
function at compile time
URL: https://github.com/apache/thrift/pull/1624#issuecomment-437853849
 
 
   @jeking3 These changes look good. Could they be merged please? All the 
cross-tests pass. Two build failures: SBCL (same issue as before) and D.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16683161#comment-16683161
 ] 

ASF GitHub Bot commented on THRIFT-4662:


jeikabu commented on a change in pull request #1624: THRIFT-4662: Rust const 
string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232526420
 
 

 ##
 File path: lib/rs/test/thrifts/Base_One.thrift
 ##
 @@ -37,6 +37,9 @@ const list CommonTemperatures = [300.0, 450.0]
 
 const double MealsPerDay = 2.5;
 
+const string DefaultRecipeName = "Something"
 
 Review comment:
   Glad to know my mastery of bad puns may finally be put to good use.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16683143#comment-16683143
 ] 

ASF GitHub Bot commented on THRIFT-4662:


jeikabu commented on a change in pull request #1624: THRIFT-4662: Rust const 
string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232522246
 
 

 ##
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##
 @@ -645,8 +648,8 @@ void t_rs_generator::render_const_value(const string& 
name, t_type* ttype, t_con
 throw "cannot generate simple rust constant for " + ttype->get_name();
   }
 
-  f_gen_ << "pub const " << rust_upper_case(name) << ": " << 
to_rust_type(ttype) << " = ";
-  render_const_value(ttype, tvalue);
+  f_gen_ << "pub const " << rust_upper_case(name) << ": " << 
to_rust_const_type(ttype) << " = ";
+  render_const_value(ttype, tvalue, false);
 
 Review comment:
   Right


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-11 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682888#comment-16682888
 ] 

ASF GitHub Bot commented on THRIFT-4662:


allengeorge commented on issue #1624: THRIFT-4662: Rust const string calls 
function at compile time
URL: https://github.com/apache/thrift/pull/1624#issuecomment-437673078
 
 
   No - that’s ok. I’ve set the minimum Rust version to 1.28 for a while now, 
so I think we should be fine.
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-10 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682737#comment-16682737
 ] 

ASF GitHub Bot commented on THRIFT-4662:


jake-ruyi commented on a change in pull request #1624: THRIFT-4662: Rust const 
string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232474522
 
 

 ##
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##
 @@ -673,15 +676,22 @@ void t_rs_generator::render_const_value_holder(const 
string& name, t_type* ttype
   f_gen_ << endl;
 }
 
-void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue) {
+void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue, 
bool isowned) {
   if (ttype->is_base_type()) {
 t_base_type* tbase_type = (t_base_type*)ttype;
 switch (tbase_type->get_base()) {
 case t_base_type::TYPE_STRING:
   if (tbase_type->is_binary()) {
-f_gen_ << "\"" << tvalue->get_string() << "\""<<  
".to_owned().into_bytes()";
+if (isowned) {
 
 Review comment:
   That explains it.  I could have sworn it needed to be `&'static`, but I 
found a bunch of examples that were `` and assumed I was thinking of 
something else...
   Do you think it's worth outputting `&'static str` instead so it works with 
Rust <1.17?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-10 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682738#comment-16682738
 ] 

ASF GitHub Bot commented on THRIFT-4662:


jake-ruyi commented on a change in pull request #1624: THRIFT-4662: Rust const 
string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232474522
 
 

 ##
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##
 @@ -673,15 +676,22 @@ void t_rs_generator::render_const_value_holder(const 
string& name, t_type* ttype
   f_gen_ << endl;
 }
 
-void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue) {
+void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue, 
bool isowned) {
   if (ttype->is_base_type()) {
 t_base_type* tbase_type = (t_base_type*)ttype;
 switch (tbase_type->get_base()) {
 case t_base_type::TYPE_STRING:
   if (tbase_type->is_binary()) {
-f_gen_ << "\"" << tvalue->get_string() << "\""<<  
".to_owned().into_bytes()";
+if (isowned) {
 
 Review comment:
   That explains it.  I could have sworn it needed to be `&'static`, but I 
found a bunch of examples that were `` and it compiled so I assumed I was 
thinking of something else...
   Do you think it's worth outputting `&'static str` instead so it works with 
Rust <1.17?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-10 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682470#comment-16682470
 ] 

ASF GitHub Bot commented on THRIFT-4662:


allengeorge commented on a change in pull request #1624: THRIFT-4662: Rust 
const string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232455479
 
 

 ##
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##
 @@ -3076,6 +3086,21 @@ string t_rs_generator::to_rust_field_type_enum(t_type* 
ttype) {
   throw "cannot find TType for " + ttype->get_name();
 }
 
+string t_rs_generator::to_rust_const_type(t_type* ttype, bool ordered_float) {
 
 Review comment:
   Please reorder implementation just before `to_rust_type`


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-10 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682471#comment-16682471
 ] 

ASF GitHub Bot commented on THRIFT-4662:


allengeorge commented on issue #1624: THRIFT-4662: Rust const string calls 
function at compile time
URL: https://github.com/apache/thrift/pull/1624#issuecomment-437592044
 
 
   @jake-ruyi Thank you for the PR. I've some minor comments, but overall this 
looks good. If you can address them, I'll approve and this can be merged in.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-10 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682469#comment-16682469
 ] 

ASF GitHub Bot commented on THRIFT-4662:


allengeorge commented on a change in pull request #1624: THRIFT-4662: Rust 
const string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232455435
 
 

 ##
 File path: lib/rs/test/thrifts/Base_One.thrift
 ##
 @@ -37,6 +37,9 @@ const list CommonTemperatures = [300.0, 450.0]
 
 const double MealsPerDay = 2.5;
 
+const string DefaultRecipeName = "Something"
 
 Review comment:
   This is incredibly minor, but, could you please choose some funny recipe 
names here? :)


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-10 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682466#comment-16682466
 ] 

ASF GitHub Bot commented on THRIFT-4662:


allengeorge commented on a change in pull request #1624: THRIFT-4662: Rust 
const string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232455248
 
 

 ##
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##
 @@ -127,7 +127,7 @@ class t_rs_generator : public t_generator {
   void render_const_value_holder(const string& name, t_type* ttype, 
t_const_value* tvalue);
 
   // Write the actual const value - the right side of a const definition.
-  void render_const_value(t_type* ttype, t_const_value* tvalue);
+  void render_const_value(t_type* ttype, t_const_value* tvalue, bool isowned = 
true);
 
 Review comment:
   Could you change parameter name to `owned` or `is_owned`?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-10 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682467#comment-16682467
 ] 

ASF GitHub Bot commented on THRIFT-4662:


allengeorge commented on a change in pull request #1624: THRIFT-4662: Rust 
const string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232455421
 
 

 ##
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##
 @@ -673,15 +676,22 @@ void t_rs_generator::render_const_value_holder(const 
string& name, t_type* ttype
   f_gen_ << endl;
 }
 
-void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue) {
+void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue, 
bool isowned) {
 
 Review comment:
   Please rename parameter to `owned` or `is_owned`.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-10 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682468#comment-16682468
 ] 

ASF GitHub Bot commented on THRIFT-4662:


allengeorge commented on a change in pull request #1624: THRIFT-4662: Rust 
const string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232455395
 
 

 ##
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##
 @@ -645,8 +648,8 @@ void t_rs_generator::render_const_value(const string& 
name, t_type* ttype, t_con
 throw "cannot generate simple rust constant for " + ttype->get_name();
   }
 
-  f_gen_ << "pub const " << rust_upper_case(name) << ": " << 
to_rust_type(ttype) << " = ";
-  render_const_value(ttype, tvalue);
+  f_gen_ << "pub const " << rust_upper_case(name) << ": " << 
to_rust_const_type(ttype) << " = ";
+  render_const_value(ttype, tvalue, false);
 
 Review comment:
   Interesting. This works because the call isn't recursive. Only the top-level 
type will be owned/static. The types in containers will all be owned because of 
the internal call to `to_rust_type`.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-10 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682465#comment-16682465
 ] 

ASF GitHub Bot commented on THRIFT-4662:


allengeorge commented on a change in pull request #1624: THRIFT-4662: Rust 
const string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232455341
 
 

 ##
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##
 @@ -414,6 +414,9 @@ class t_rs_generator : public t_generator {
   // Return a string representing the rift `protocol::TType` given a `t_type`.
   string to_rust_field_type_enum(t_type* ttype);
 
+  // Return a string representing the `const` rust type given a `t_type`
+  string to_rust_const_type(t_type* ttype, bool ordered_float = true);
 
 Review comment:
   Good call. Makes sense to split this out from the `to_rust_type`. Could you 
please put this function declaration right before `to_rust_type`? And do the 
same for implementation please? It just ensures that code that has similar 
functionality is in the same part of the file.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-10 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682454#comment-16682454
 ] 

ASF GitHub Bot commented on THRIFT-4662:


allengeorge commented on a change in pull request #1624: THRIFT-4662: Rust 
const string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232454772
 
 

 ##
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##
 @@ -673,15 +676,22 @@ void t_rs_generator::render_const_value_holder(const 
string& name, t_type* ttype
   f_gen_ << endl;
 }
 
-void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue) {
+void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue, 
bool isowned) {
   if (ttype->is_base_type()) {
 t_base_type* tbase_type = (t_base_type*)ttype;
 switch (tbase_type->get_base()) {
 case t_base_type::TYPE_STRING:
   if (tbase_type->is_binary()) {
-f_gen_ << "\"" << tvalue->get_string() << "\""<<  
".to_owned().into_bytes()";
+if (isowned) {
 
 Review comment:
   No - the PR isn't being held up because of const binary. I just didn't have 
time to look at it yet. I usually pull the branch locally and test in a 
container to ensure everything works. For one thing, I'm unsure that
   
   ```
   const FOO:  = "ladeda";
   ```
   
   works in rust 1.28.
   
   EDIT. Oh, nm - I see it was [enabled in 
1.17](https://rust-lang-nursery.github.io/edition-guide/rust-2018/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.html)


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-09 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16682130#comment-16682130
 ] 

ASF GitHub Bot commented on THRIFT-4662:


jake-ruyi commented on a change in pull request #1624: THRIFT-4662: Rust const 
string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r232434691
 
 

 ##
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##
 @@ -673,15 +676,22 @@ void t_rs_generator::render_const_value_holder(const 
string& name, t_type* ttype
   f_gen_ << endl;
 }
 
-void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue) {
+void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue, 
bool isowned) {
   if (ttype->is_base_type()) {
 t_base_type* tbase_type = (t_base_type*)ttype;
 switch (tbase_type->get_base()) {
 case t_base_type::TYPE_STRING:
   if (tbase_type->is_binary()) {
-f_gen_ << "\"" << tvalue->get_string() << "\""<<  
".to_owned().into_bytes()";
+if (isowned) {
 
 Review comment:
   My goals were:
   1. Make `const binary` compile
   2. Preserve existing behavior
   
   Presently, neither `const string` nor `const binary` compiles. I'm more 
interested in getting our stuff compiling than addressing the semantics of 
`binary`. Should I revert the binary portion?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-07 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16678281#comment-16678281
 ] 

ASF GitHub Bot commented on THRIFT-4662:


jake-ruyi commented on a change in pull request #1624: THRIFT-4662: Rust const 
string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r231521483
 
 

 ##
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##
 @@ -673,15 +676,22 @@ void t_rs_generator::render_const_value_holder(const 
string& name, t_type* ttype
   f_gen_ << endl;
 }
 
-void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue) {
+void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue, 
bool isowned) {
   if (ttype->is_base_type()) {
 t_base_type* tbase_type = (t_base_type*)ttype;
 switch (tbase_type->get_base()) {
 case t_base_type::TYPE_STRING:
   if (tbase_type->is_binary()) {
-f_gen_ << "\"" << tvalue->get_string() << "\""<<  
".to_owned().into_bytes()";
+if (isowned) {
 
 Review comment:
   Honestly, I'm not really sure about the byte-arrays.  We aren't using them 
anywhere, so I'm not clear on the use-cases.
   I assume it will end up like the regular strings where you might want 
`map` or something like that.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-07 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16678211#comment-16678211
 ] 

ASF GitHub Bot commented on THRIFT-4662:


allengeorge commented on issue #1624: THRIFT-4662: Rust const string calls 
function at compile time
URL: https://github.com/apache/thrift/pull/1624#issuecomment-436619709
 
 
   @jake-ruyi Thank you for the bug report - and the PR! I've asked a question 
about the implementation.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-07 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16678210#comment-16678210
 ] 

ASF GitHub Bot commented on THRIFT-4662:


allengeorge commented on a change in pull request #1624: THRIFT-4662: Rust 
const string calls function at compile time
URL: https://github.com/apache/thrift/pull/1624#discussion_r231499393
 
 

 ##
 File path: compiler/cpp/src/thrift/generate/t_rs_generator.cc
 ##
 @@ -673,15 +676,22 @@ void t_rs_generator::render_const_value_holder(const 
string& name, t_type* ttype
   f_gen_ << endl;
 }
 
-void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue) {
+void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue, 
bool isowned) {
   if (ttype->is_base_type()) {
 t_base_type* tbase_type = (t_base_type*)ttype;
 switch (tbase_type->get_base()) {
 case t_base_type::TYPE_STRING:
   if (tbase_type->is_binary()) {
-f_gen_ << "\"" << tvalue->get_string() << "\""<<  
".to_owned().into_bytes()";
+if (isowned) {
 
 Review comment:
   Will there ever be a point where we want the const string/byte-array to be 
owned?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Assignee: Allen George
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-07 Thread J W (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16677895#comment-16677895
 ] 

J W commented on THRIFT-4662:
-

Created PR:

https://github.com/apache/thrift/pull/1624

> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (THRIFT-4662) Rust const string calls function at compile time

2018-11-07 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/THRIFT-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16677894#comment-16677894
 ] 

ASF GitHub Bot commented on THRIFT-4662:


jake-ruyi opened a new pull request #1624: THRIFT-4662: Rust const string calls 
function at compile time
URL: https://github.com/apache/thrift/pull/1624
 
 
   Client: rs
   
   Fix with simple test


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust const string calls function at compile time
> 
>
> Key: THRIFT-4662
> URL: https://issues.apache.org/jira/browse/THRIFT-4662
> Project: Thrift
>  Issue Type: Bug
>  Components: Rust - Compiler
>Affects Versions: 0.11.0
> Environment: C:\Users\jake>rustup show
> Default host: x86_64-pc-windows-msvc
> stable-x86_64-pc-windows-msvc (default)
> rustc 1.30.0 (da5f414c2 2018-10-24)
>Reporter: J W
>Priority: Major
>
> *For this thrift:*
> const string broker_playback_message = "mmi.developer.playback"
> *Generates:*
> // thrift -gen rs -out ../rust/thrift/src const_string.thrift
> pub const BROKER_PLAYBACK_MESSAGE: String = 
> "mmi.developer.playback".to_owned();
> *Fails to compile:*
> error[E0015]: calls in constants are limited to tuple structs and tuple 
> variants
> note: a limited form of compile-time function evaluation is available on a 
> nightly compiler via `const fn`
> *Fix:*
> Probably want to output:
> pub const BROKER_PLAYBACK_MESSAGE:  = "mmi.developer.playback";
>  
> Looking at render_const_value() it looks like byte arrays will have the same 
> issue.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)